我目前正在尝试向我的 Arduino Yun 发送一个字符串,并试图让它根据我发送的内容回复。
我在这里选择了一些代码的框架并一直在尝试它,但除了显示“准备就绪”的串行监视器之外,我无法让它更进一步。
代码是:
//declace a String to hold what we're inputting
String incomingString;
void setup() {
//initialise Serial communication on 9600 baud
Serial.begin(9600);
while(!Serial);
//delay(4000);
Serial.println("Ready!");
// The incoming String built up one byte at a time.
incomingString = "";
}
void loop () {
// Check if there's incoming serial data.
if (Serial.available() > 0) {
// Read a byte from the serial buffer.
char incomingByte = (char)Serial.read();
incomingString += incomingByte;
// Checks for null termination of the string.
if (incomingByte == '\0') {
// ...do something with String...
if(incomingString == "hello") {
Serial.println("Hello World!");
}
incomingString = "";
}
}
}
谁能指出我正确的方向?
谢谢