跳至内容
用户工具
站点工具
搜索
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
m:ws:ws2
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== Workshop 2 ====== 学习如何使用Arduino的串口通信 ''#include <stdio.h> String inputString = ""; // a string to hold incoming data boolean stringComplete = false; // whether the string is complete void setup() { // initialize serial: Serial.begin(9600); // reserve 200 bytes for the inputString: inputString.reserve(200); } void loop() { //serialEvent(); //call the function // print the string when a newline arrives: int num = 0; if (stringComplete) { Serial.println(inputString); sscanf(inputString.c_str(), "R%d",&num); Serial.println(num); // clear the string: inputString = ""; stringComplete = false; } } /* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */ void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } } }''
· 最后更改: 2015/11/07 13:17
页面工具
显示页面
修订记录
反向链接
回到顶部