本帖最后由 Yuanq 于 2020-8-5 23:40 编辑
BlinkerButton Kelvinator_power("btn-pwr");
BlinkerButton Kelvinator_Light("btn-deng");
BlinkerSlider Slider1("ran-wen");
BlinkerNumber NUM2("settemp");
BlinkerSlider Slider2("ran-fan");
BlinkerNumber NUM1("fan");
BlinkerButton Kelvinator_sxfan("btn-sx");
void setup() {
Serial.begin(115200);
Kelvinator_power.attach(Kelvinator_power_callback);
Kelvinator_Light.attach(Kelvinator_Light_callback);
Kelvinator_sxfan.attach(Kelvinator_sxfan_callback);
Slider1.attach(slider1_callback);
Slider2.attach(slider2_callback);
delay(200);
Blinker.begin(auth,ssid,pswd);
}
void loop() {
Blinker.run();
}
void Kelvinator_power_callback(const String &state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_ON)
{
Serial.println("pwr on");
Kelvinator_power.print("on");
}else if (state == BLINKER_CMD_OFF){
Kelvinator_power.print("off");
}
}
void Kelvinator_Light_callback(const String &state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_ON)
{
Serial.println("light on");
Kelvinator_Light.print("on");
}else if (state == BLINKER_CMD_OFF){
Serial.println("light off");
Kelvinator_Light.print("off");
}
}
void slider1_callback(int32_t value)
{
BLINKER_LOG("get slider value: ", value);
Serial.println(value);
}
void slider2_callback(int32_t value)
{
BLINKER_LOG("get slider value: ", value);
Serial.println(value);
}
void Kelvinator_sxfan_callback(const String &state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_ON)
{ Kelvinator_sxfan.print("on");
Serial.println("updown on");
}else if (state == BLINKER_CMD_OFF){
Serial.println("updown off");
Kelvinator_sxfan.print("off");
}
}
所有按键均为开关类型
第一次进入控制界面时,任意点击一个按钮,都只会调用该按钮的函数,之后点击另一个按钮,不但会执行该按钮的函数,还会执行上一个点击过的按钮的函数,再点击第三个按钮,就会三个按钮的函数都执行
比如:刚打开界面时,点击第一个按钮,串口打印pwr on,此时点击第二个按钮,串口打印pwr on \n light on,点击第三个按钮打印pwr on \n light on \n updown on
拖动第一个滑动条到19,打印pwr on \n light on \n updown on \n 19,拖动第二个滑动条到3,打印pwr on \n light on \n updown on \n 19 \n 3
再点击一下第一个按钮,打印pwr off \n light on \n updown \n on \n 19 \n 3
|