本帖最后由 yuanxi 于 2021-8-14 14:35 编辑
所需材料:ESP8266 ch340 6路继电器 实现用点灯科技(blinker)APP远程开关
- #define BLINKER_WIFI
- #include <Blinker.h>
- char auth[] = "e93f"; // 点灯科技秘钥
- char ssid[] = "wifi"; // WiFi名称
- char pswd[] = "123456"; // WiFi密码
- #define bt1 5
- #define bt2 4
- #define bt3 0
- #define bt4 2
- // 新建组件对象
- BlinkerButton Button1("btn1-abc");
- BlinkerButton Button2("btn2-abc");
- BlinkerButton Button3("btn3-abc");
- BlinkerButton Button4("btn4-abc");
- // 按下按键即会执行该函数
- void button1_callback(const String & state) {
- BLINKER_LOG("get button state: ", state);
- if (state == "on") {
- digitalWrite(bt1, LOW);
- // 反馈开关状态
- Button1.print("on");
- } else if (state == "off") {
- digitalWrite(bt1, HIGH);
- // 反馈开关状态
- Button1.print("off");
- }
- }
- // 按下按键即会执行该函数
- void button2_callback(const String & state) {
- BLINKER_LOG("get button state: ", state);
- if (state == "on") {
- digitalWrite(bt2, LOW);
- // 反馈开关状态
- Button2.print("on");
- } else if (state == "off") {
- digitalWrite(bt2, HIGH);
- // 反馈开关状态
- Button2.print("off");
- }
- }
- // 按下按键即会执行该函数
- void button3_callback(const String & state) {
- BLINKER_LOG("get button state: ", state);
- if (state == "on") {
- digitalWrite(bt3, LOW);
- // 反馈开关状态
- Button3.print("on");
- } else if (state == "off") {
- digitalWrite(bt3, HIGH);
- // 反馈开关状态
- Button3.print("off");
- }
- }
- // 按下按键即会执行该函数
- void button4_callback(const String & state) {
- BLINKER_LOG("get button state: ", state);
- if (state == "on") {
- digitalWrite(bt4, LOW);
- // 反馈开关状态
- Button4.print("on");
- } else if (state == "off") {
- digitalWrite(bt4, HIGH);
- // 反馈开关状态
- Button4.print("off");
- }
- }
- void setup() {
- // 初始化串口
- Serial.begin(115200);
- // 初始化有LED的IO
- pinMode(bt1, OUTPUT);
- digitalWrite(bt1, HIGH);
- pinMode(bt2, OUTPUT);
- digitalWrite(bt2, HIGH);
- pinMode(bt3, OUTPUT);
- digitalWrite(bt3, HIGH);
- pinMode(bt4, OUTPUT);
- digitalWrite(bt4, HIGH);
- // 初始化blinker
- Blinker.begin(auth, ssid, pswd);
- Button1.attach(button1_callback);
- Button2.attach(button2_callback);
- Button3.attach(button3_callback);
- Button4.attach(button4_callback);
- }
- void loop() {
- Blinker.run();
- }
- ————————————————
- 感谢群友 尨行 帮忙完善
复制代码
|