手机点灯控制ESP8266板载LED

#define BLINKER_PRINT Serial
#define BLINKER_WIFI

#include <Blinker.h>

char auth[] = "c9876669831c"; //上一步中在app中获取到的Secret Key
char ssid[] = "ChinaNet-Ks22"; //您的WiFi热点名称
char pswd[] = "12345678"; //您的WiFi密码

#include <Arduino.h>

BlinkerButton button("btn");

void button1_callback(const String & state)
{
    if (state == "on") {
        digitalWrite(LED_BUILTIN, LOW);
        button.text("已打开");
        button.print("on");

    }else {
        digitalWrite(LED_BUILTIN, HIGH);
        button.text("已关闭");
        button.print("off");


    }
}
void setup() {
// write your initialization code here
    Serial.begin(115200);
    // 初始化有LED的IO
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH); //高电频默认关闭
    // 初始化blinker
    Blinker.begin(auth, ssid, pswd);
    // Blinker.attachData(dataRead);
    button.attach(button1_callback);
}

void loop() {
// write your code here
    Blinker.run();
}
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps = Blinker@^0.3.10230510
monitor_speed = 115200

  

  

posted @ 2024-08-16 22:49  李兴利  阅读(12)  评论(0编辑  收藏  举报