[codesyntax lang=”cpp”]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/* * http://surenpi.com * Hello World for arduino seiral communication. */ #include <Stepper.h> String strData = ""; void setup() { Serial.begin(9600); } void loop() { while(Serial.available() > 0) { strData += char(Serial.read()); delay(2); } if(strData.length() > 0) { Serial.println(strData); strData = ""; } } |
上面的例子中,通过Arduino IDE控制台输入什么字符串,就会打印出什么字符串。
参考:
Arduino之看门狗" href="http://surenpi.com/2015/03/13/arduino%e4%b9%8b%e7%9c%8b%e9%97%a8%e7%8b%97/" target="_blank">有关Arduino的其他文章。