PlainProtocol write 通过蓝牙发送 接收端数据时而为null

2015-03-171.1万
AI 快速预览详细 收起
本文讨论了使用PlainProtocol库通过蓝牙发送传感器数据时遇到的数据为null的问题。通过调整代码中的延迟时间和初始化顺序,可以有效解决这一问题。示例代码展示了如何读取模拟和数字传感器数据,并通过蓝牙发送。
#include <PlainProtocol.h>

PlainProtocol mytest(Serial, 57600);

const int waterPin = 10;

void setup() {
  mytest.init();
  pinMode(waterPin,INPUT);
}

void loop() {
  int t_analogValue;//analog
  t_analogValue = analogRead(0);   //connect Steam sensors to Analog 0
  int t_digitalValue = LOW; //default digital low
  t_digitalValue = digitalRead(waterPin);

  //low is sending
  if(t_digitalValue == LOW){
    mytest.write("T_A|T_D",t_analogValue,t_digitalValue);//send analogValue and digitalValue
  }
  delay(1000);
}

创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(2)
hennychen
hennychen
作者
mytest.sendFrame("T_A|T_D",2,t_analogValue,t_digitalValue);//send analogValue and digitalValue
解决方法
hennychen
hennychen
作者
有时为乱码 我获取的16进制的
e01866fe 66000606 66fe6660 f818781e 18188600
- 没有更多了 -