Arduino 串口数据读写

源代码:


char teststring;

void setup() {

 Serial.begin(9600);   //串口和Arduino之间的通信

   }

void loop() {

 while(Serial.available()>0){

   teststring = Serial.read();

    Serial.println(teststring);

   delay(1000); 

  }

}

输出结果:


备注:


使用read()函数时,每次只能读取1字节的数据,如果要读取一个字符串,可以使用“+=”运算符将字符依次添加到字符串中,此处参考《Arduino程序设计基础》中的示例:

完    

2018/06/21

猜你喜欢

转载自blog.csdn.net/weixin_42385626/article/details/81096182