anandexuechengzhangzhilu

需要用到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:
}

分类:

技术点:

相关文章:

  • 2021-08-01
  • 2021-10-26
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
猜你喜欢
  • 2021-08-20
  • 2022-12-23
  • 2021-09-13
  • 2021-07-11
  • 2022-02-02
  • 2022-12-23
  • 2022-03-02
相关资源
相似解决方案