使用列表页快捷开关-Arduino中文社区 - Powered by Discuz! Archiver

coloz 发表于 2019-6-18 21:14

使用列表页快捷开关

Blinker App在设备列表页提供了快捷开关设备的功能,使用方法如下:




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();
}




页: [1]
查看完整版本: 使用列表页快捷开关