zoukankan      html  css  js  c++  java
  • Arduino

    需要用到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:
    }
  • 相关阅读:
    第四周学习报告
    第三周学习报告
    第二周学习报告
    第一周学习报告
    大创首月学习计划
    20183122 综合实验《Python程序设计》实验报告
    20183122 实验三《Python程序设计》实验报告
    20183122 实验二《Python程序设计》实验报告
    数据存储和JSON,CSV
    python模块那点事
  • 原文地址:https://www.cnblogs.com/anandexuechengzhangzhilu/p/10719111.html
Copyright © 2011-2022 走看看