|
本帖最后由 ahua7336 于 2020-6-18 15:38 编辑
blinker+433Mhz超外差模块 注册2个按键程序正常运行 注册4个按键程序就无反应了!
代码如下↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
#define BLINKER_WIFI
#include <RCSwitch.h>
#include <Blinker.h>
RCSwitch mySwitch = RCSwitch();
char auth[] = "3ccd7e*****"; // 注册AAP时的KEY
char ssid[] = "HUAWEI-*****"; // 你的wifi名字
char pswd[] = "hero*****"; // 你的wifi密码
//新建组件对象
BlinkerButton Button1("btn-km");
BlinkerButton Button2("btn-gm");
BlinkerButton Button3("btn-tz");
BlinkerButton Button4("btn-sd");
BlinkerText txt1("tex-zt");
//按下开门按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("调试输出:", state);
if (state == "tap")
{
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
txt1.print("开门");
mySwitch.send("010010101101010110010110"); //433按键输出
Blinker.vibrate(); //手机震动
digitalWrite(LED_BUILTIN, HIGH);
Blinker.delay(500);
digitalWrite(LED_BUILTIN, LOW);
BLINKER_LOG("调试输出:", state);
}
else if (state == "press")
{
txt1.print("开门");
BLINKER_LOG("调试输出:", state);
}
else
{
txt1.print("停止");
BLINKER_LOG("调试输出:", state);
}
}
//按下关门按键即会执行该函数
void button2_callback(const String & state) {
BLINKER_LOG("调试输出:", state);
if (state == "tap")
{
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
txt1.print("关门");
mySwitch.send("010010101101010110011010"); //433按键输出
Blinker.vibrate(); //手机震动
digitalWrite(LED_BUILTIN, HIGH);
Blinker.delay(500);
digitalWrite(LED_BUILTIN, LOW);
BLINKER_LOG("调试输出:", state);
}
}
//按下停止按键即会执行该函数
void button3_callback(const String & state) {
BLINKER_LOG("调试输出:", state);
if (state == "tap")
{
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
txt1.print("停止");
mySwitch.send("010010101101010110011000"); //433按键输出
Blinker.vibrate(); //手机震动
digitalWrite(LED_BUILTIN, HIGH);
Blinker.delay(500);
digitalWrite(LED_BUILTIN, LOW);
BLINKER_LOG("调试输出:", state);
}
}
//按下锁定按键即会执行该函数
void button4_callback(const String & state) {
BLINKER_LOG("调试输出:", state);
if (state == "tap")
{
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
txt1.print("停止");
mySwitch.send("010010101101010110010100"); //433按键输出
Blinker.vibrate(); //手机震动
digitalWrite(LED_BUILTIN, HIGH);
Blinker.delay(500);
digitalWrite(LED_BUILTIN, LOW);
BLINKER_LOG("调试输出:", state);
}
}
void setup() {
// 初始化串口,并开启调试信息
Serial.begin(9600);
BLINKER_DEBUG.stream(Serial);
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// 初始化433遥控
mySwitch.enableTransmit(10); //433遥控
mySwitch.setPulseLength(340); //433遥控
// 初始化blinker
Blinker.begin(auth,ssid,pswd,0,1); //联网初始化
Button1.attach(button1_callback); //注册开门按键函数
Button2.attach(button2_callback); //注册关门按键函数
Button3.attach(button3_callback); //注册停止按键函数
Button4.attach(button4_callback); //注册锁定按键函数
}
void loop() {
Blinker.run();
}
大神帮忙看下 本人属于小白!!
解决办法:
此条发射指令(数据二进制) mySwitch.send("010010101101010110010100"); //433按键输出
更换为十进制数据 程序就正常了 mySwitch.send(4904340, 24); //433按键输出
|
|