Blinker App在设备列表页提供了快捷开关设备的功能,使用方法如下:
[mw_shl_code=arduino,true]
bool ledState=true;
void heartbeat() {
BLINKER_LOG("heartbeat!");
if(ledState)
BUILTIN_SWITCH.print("on");
else
BUILTIN_SWITCH.print("off");
}
void switch_callback(const String & state) {
BLINKER_LOG("get switch state: ", state);
if (state == BLINKER_CMD_ON) {
digitalWrite(LED_BUILTIN, HIGH);
BUILTIN_SWITCH.print("on");
}
else {
digitalWrite(LED_BUILTIN, LOW);
BUILTIN_SWITCH.print("off");
}
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, type);
Blinker.attachHeartbeat(heartbeat);
BUILTIN_SWITCH.attach(switch_callback);
#if defined(BLINKER_BUTTON)
Blinker.attachClick(singalClick);
Blinker.attachDoubleClick(doubleClick);
attachInterrupt(BLINKER_BUTTON_PIN, buttonTick, CHANGE);
#endif
}
void loop()
{
Blinker.run();
}
[/mw_shl_code]
|