/*Test the communication between ROS and arduino throuth serial
bob
2016,1,9
*/
char byte1;
String str1 = "";
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
while (Serial.available() > 0)
{
str1 += char(Serial.read());
}
if (str1.length() > 4)
{
Serial.println(str1);
str1 = "";
}
Serial.println("Good night");
digitalWrite(13, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(500); // wait for a second
}

本文介绍了一个简单的Arduino程序,用于测试Arduino与ROS之间的串口通信。程序通过串口接收数据,并在接收到超过四个字符的数据时打印出来。此外,程序还控制了Arduino板上的LED进行亮灭循环。
1452

被折叠的 条评论
为什么被折叠?



