String comdata="";
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
Serial.begin(9600);
while(Serial.read() >= 0){}
Serial.println(“Begin”);
}
void loop() {
// put your main code here, to run repeatedly:
ReceiveWifiMessage();
if(comdata.length()>0){
Serial.println(comdata);
if(comdata.compareTo(“open”)>0){
Serial.println(“Light”);
digitalWrite(13, HIGH); // 将LED点亮(HIGH代表高电压)
}else{
Serial.println(“Dark”);
digitalWrite(13, LOW); // 将LED熄灭(LOW代表低压)
}
}
}
/**
- 读取串口缓冲区里面的数据
*/
void ReceiveWifiMessage(){
comdata="";
while (Serial.available() > 0 )
{
comdata+=char(Serial.read());
delay(2);
}
}
版权声明:本文为CSDN博主「只想长高」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43132322/article/details/122596816
暂无评论