Arduino 如何正确发送、接收和存储响应?
我正在学习,因为像这样的论坛上的人指导了我 我刚刚学习了如何使用串行通信向传感器发送请求,我使用以下代码查询传感器。预期的查询是:Arduino 如何正确发送、接收和存储响应?,arduino,Arduino,我正在学习,因为像这样的论坛上的人指导了我 我刚刚学习了如何使用串行通信向传感器发送请求,我使用以下代码查询传感器。预期的查询是: digitalWrite(mdDeRe, HIGH); //tells the sensor serial data is coming. Serial.write(17); Serial.write(3); Serial.write(0); Serial.write(84); Serial.write(0); Serial.w
digitalWrite(mdDeRe, HIGH); //tells the sensor serial data is coming.
Serial.write(17);
Serial.write(3);
Serial.write(0);
Serial.write(84);
Serial.write(0);
Serial.write(4);
Serial.write(7);
Serial.write(73);
Serial.flush();
delayMicroseconds(120);
digitalWrite(mdDeRe,LOW);
///sensor response is: 11 03 08 00 64 00 3E 00 0D 00 55 9C E8
/// I would like to store the response in an array.
if (Serial.available()) {
for (int response=0; response<12; response ++){
incomingByte[response] = Serial.read();
}
}
}
/// Will this work?
/// Is there a more efficient or proper way to do the same?
digitalWrite(mdDeRe,高)//通知传感器串行数据即将到来。
串行写入(17);
串行写入(3);
串行写入(0);
串行写入(84);
串行写入(0);
串行写入(4);
串行写入(7);
串行写入(73);
Serial.flush();
延迟微秒(120);
数字写入(mdDeRe,低位);
///传感器响应为:11 03 08 00 64 00 3E 00 0D 00 55 9C E8
///我想将响应存储在一个数组中。
if(Serial.available()){
对于(int response=0;response)我认为您的问题标记错误,这真的是javascript,还是java?嗨!实际上它来自Arduino IDE。您希望在一个字节可用后,其他字节也可用。这不是真的。字节到达速度很慢。Serial.available()在接收缓冲区中可用的字符返回计数。在收到ActhSuldio程序之前,不要再发送任何请求,除非是用C++编程,而不是JavaScript。请在这里发布问题的最小的研究。至少阅读ARDUIO手册。尤拉伊,谢谢您的时间!这会更好吗?(Serial.available()>12){for(int-response=0;response