需要用到Arduino UNO的串口双向通信功能,以下源码:


int val; void setup() {   Serial.begin(9600); // opensserial port, sets data rate to 9600 bps     while(Serial.read()>= 0){}//clear serialbuffer  }   void loop() {   if (Serial.available() > 0) {      delay(100); // 等待数据传完      int numdata = Serial.available();      val=Serial.read();     Serial.println(val);     if(val==49)     {       Serial.println("Test OK");        Serial.println(val);      }     while(Serial.read()>=0){} //清空串口缓存    }    // put your main code here, to run repeatedly: }   串口调试
int val; void setup() {   Serial.begin(9600); // opensserial port, sets data rate to 9600 bps     while(Serial.read()>= 0){}//clear serialbuffer  }   void loop() {   if (Serial.available() > 0) {      delay(100); // 等待数据传完      int numdata = Serial.available();      val=Serial.read();     Serial.println(val);     if(val==49)     {       Serial.println("Test OK");        Serial.println(val);      }     while(Serial.read()>=0){} //清空串口缓存    }    // put your main code here, to run repeatedly: }
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。