blinker连接蓝牙,蓝牙连接nano问题
这个是我的代码,我想实现用blinker连接蓝牙,蓝牙连接nano的板子。问题是:能够连上蓝牙,板子也收到了,板子的tx指示灯也亮了,但是就是不执行回调函数。
#define BLINKER_BLE
#include <Blinker.h>
BlinkerButton Button1("btn-1"); //对应blinker库里面的四个按键
BlinkerButton Button2("btn-2");
BlinkerButton Button3("btn-3");
BlinkerButton Button4("btn-4");
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state=="press")
{
digitalWrite(2,1);
delay(200);
}
else
{digitalWrite(2,0);
}
}
void button2_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state=="press")
{
digitalWrite(3,1);
delay(200);
}
else
{digitalWrite(3,0);
}
}
void button3_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state=="press")
{
digitalWrite(4,1);
delay(200);
}
else
{digitalWrite(4,0);
}
}
void button4_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state=="press")
{
digitalWrite(5,1);
delay(200);
}
else
{digitalWrite(5,0);
}
}
//初始化定义
void setup() {
Serial.begin(9600);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
digitalWrite(2,0);
digitalWrite(3,0);
digitalWrite(4,0);
digitalWrite(5,0);
Blinker.begin(0,1,9600); //设置单片机板子的(RX,TX,bps)
Button1.attach(button1_callback); //回调函数
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
}
void loop() {
Blinker.run();
}
1.请先测试例程
2.回调中不能有delay 使用默认串口进行通讯,还关闭了blinker串口输出,能显示东西就有鬼了
页:
[1]