|
本帖最后由 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();
}
|
|