本帖最后由 啥b 于 2021-10-20 17:02 编辑
[md]void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(12,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available() > 0) {//检查缓冲区是否有数据,不断循环到缓冲区数据为0
char ch =+ Serial.read();
delay(10); //设置缓冲防止数据丢失
}
if(ch == "open"){
Serial.println("led is open");
digitalWrite(12,HIGH);
}
else if(ch == "close"){
Serial.println("led is off");
digitalWrite(12,LOW);
}
}[/md]
想使用while循环来实现多字节却在循环外读取不了,不知道是不是哪里缺了什么
|