我怎么到这个code通过Arduino的,使音频播放我的电脑音箱? [英] What do I add to this code to make the audio play out of my PC speakers via Arduino?

查看:337
本文介绍了我怎么到这个code通过Arduino的,使音频播放我的电脑音箱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在上一个Arduino这个code。使用Arduino的,是有办法的音频传递给我的PC喇叭?

  //这将导入音频类
#包括LT&;&PCM.h GT;//这是所播放的声音
常量无符号字符Sound1例子[] PROGMEM = {129,127,126,127,128,128,128,12};//常量变量
const int的knockSensor = A0;
const int的阈值1 = 10;//这个创建一个变量
INT sensorReading = 0;无效设置(){
    Serial.begin(9600);
}空隙环(){
    sensorReading = analogRead(knockSensor);
    如果(sensorReading> =阈值1){
        Serial.println(阈值1);
        startPlayback(Sound1例子,sizeof的(Sound1例子));
    }    延迟(200);
}


解决方案

假设Arduino板没有物理连接到你的电脑,你应该通过串口发送值Arduino是读书到PC。在PC上运行的程序将获得通过诗里亚端口这个值,可能的话,请使用操作系统,播放数据的声音。如果你是在Linux上,这将是很容易的,通过书面方式数据到/ dev /音频

I am running this code on an Arduino. Using the Arduino, is there a way to pass the audio to my PC speakers?

//This imports the audio class
#include <PCM.h>

//This is the sound being played
const unsigned char sound1[] PROGMEM = {129, 127, 126, 127, 128, 128, 128, 12};

//constant variables
const int knockSensor = A0;
const int threshold1 = 10;

//This create a variable
int sensorReading = 0;

void setup() {
    Serial.begin(9600);
}

void loop() {
    sensorReading = analogRead(knockSensor);
    if (sensorReading >= threshold1) {
        Serial.println(threshold1);
        startPlayback(sound1, sizeof(sound1));
    }

    delay(200);
}

解决方案

Assuming that the Arduino board isn't physically connected to your PC, you should send the value Arduino is reading to PC, via Serial. A program running at the PC would get this values via seria port and could, then, use the Operating System to play that data as sound. If you're on Linux that would be really easy, by writting data to /dev/audio

这篇关于我怎么到这个code通过Arduino的,使音频播放我的电脑音箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆