我正在Arduino上运行此代码。使用Arduino,是否可以将音频传递到PC扬声器?
//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);
}
最佳答案
假设Arduino板未物理连接到PC,则应通过Serial将Arduino读取的值发送到PC。在PC上运行的程序将通过seria端口获取此值,然后可以使用操作系统以声音形式播放该数据。如果您使用的是Linux,那么将数据写入/ dev / audio会非常容易
关于audio - 我要在此代码中添加些什么,以使音频通过Arduino在PC扬声器中播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9610645/