全套工具下载地址
我的百度网盘链接
链接:https://pan.baidu.com/s/1mdI6iD4J9bLlBvbdE7CX3g
提取码:l548
本课程所需要的基础
arduino IED编写ESP8266 环境搭建与程序下载 教程
最小系统电路图
image.png操作步骤如下,blinker官方网站
https://diandeng.tech/doc/home
在blinker App上新建一个按钮 按钮的数据键名叫 btn
blinker APP控制esp8266的灯
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "b7d4ed6a242d";
char ssid[] = "bad123";
char pswd[] = "1234567890";
// 新建组件对象
BlinkerButton Button1("btn");
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
}
void setup() {
// 初始化串口
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
}
void loop() {
Blinker.run();
}
最终小爱同学控制亮度和开关
#define BLINKER_WIFI
#define BLINKER_MIOT_LIGHT
#define BLINKER_PRINT Serial
#include <Blinker.h>
char auth[] = "b7d4ed6a242d";
char ssid[] = "bad123";
char pswd[] = "1234567890";
// 新建组件对象
BlinkerButton Button1("btn");
void miotBright(const String & bright)
{
int colorW;
BLINKER_LOG("need set brightness: ", bright);
colorW = bright.toInt();
analogWrite(LED_BUILTIN,1023-colorW*10.23);//0-1023
BLINKER_LOG("now set brightness: ", colorW);
BlinkerMIOT.brightness(colorW);
BlinkerMIOT.print();
}
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
digitalWrite(LED_BUILTIN, LOW);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(LED_BUILTIN, HIGH);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
}
}
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
}
void setup() {
// 初始化串口
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachBrightness(miotBright);
}
void loop() {
Blinker.run();
}
网友评论