求大神写一个ESP-01s加继电器模块电灯科技控制电脑开机
本人小白。手里有esp-01s的板子和继电器模块,,刷入点灯平台,想实现这样的功能默认继电器关闭,点击app开以后控制继电器开2秒在关闭,控制电脑开关机可以代写 用如下范例试试 本帖最后由 dmnkkang 于 2021-1-2 19:22 编辑
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "***";
char ssid[] = "***";
char pswd[] = "***";
#define BUTTON_1 "btn-abc"
BlinkerButton Button1(BUTTON_1);
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state =="on") {
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(0, LOW);
Button1.icon("fas fa-power-off");
Button1.color("#339af0");
Button1.text("关机中");
Button1.print("on");
Blinker.delay(2000);
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(0, HIGH);
Button1.icon("fas fa-power-off");
Button1.color("#51cf66");
Button1.text("已关机");
Button1.print("off");
Blinker.delay(3000);
Button1.icon("far fa-power-off");
Button1.text("按键关");
Button1.print("off");
}
else if (state =="off") {
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(0, HIGH);
Button1.icon("far fa-power-off");
Button1.text("按键关");
Button1.print("off");
}
}
void setup(){
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
pinMode(0, OUTPUT);
digitalWrite(0, HIGH);
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
}
改以下字段中的2000调整继电器开关接通时间(以下为2000毫秒,即两秒)
Button1.text("关机中");
Button1.print("on");
Blinker.delay(2000); 只是简单IO控制,用示例程序就可以 dmnkkang 发表于 2021-1-2 19:15
#define BLINKER_WIFI
#include
你写这个无法连接WiFi 团子yyb 发表于 2021-1-13 10:54
你写这个无法连接WiFi
```
char ssid[] = "***";
char pswd[] = "***";
```
替换自己的wifi名称密码 raikay 发表于 2021-1-13 11:17
```
char ssid[] = "***";
char pswd[] = "***";
还是不行 控制继电器闭合2秒就行,关键是电脑状态反馈怎么做?
页:
[1]
2