void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// send an intro:
Serial.println("send any byte and I'll tell you everything I can about it");
Serial.println();
}
void loop() {
// get any incoming bytes:
if (Serial.available() > 0) {
int thisChar = Serial.read();
// say what was sent:
Serial.print("You sent me: \'");
Serial.write(thisChar);
}
1 回答
如果打开Arduino IDE,请在菜单下查看:
File > Examples > 08.Strings > CharacterAnalysis
在这里,我想你会找到一些非常接近你正在寻找的东西 . 总而言之,它打开串行连接(USB)并从计算机读取输入 . (您需要确保匹配波特率并使用“发送”按钮 . )您可以根据需要对Arduino进行编程 . 在示例中,它只是将反馈发送回串行监视器 . 自己运行,看看会发生什么:)
示例中的[MCVE]代码段: