1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#define BLINKER_WIFI

#include <Blinker.h>

char auth[] = "";
char ssid[] = "";
char pswd[] = "";

// 新建组件对象
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");
BlinkerButton led2("btn-led2");

int counter = 0;

// 按下按键即会执行该函数
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(12, !digitalRead(12));
}

void led2_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(13, !digitalRead(13));
}


// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}

void setup()
{
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();

// 初始化有LED的IO
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);

pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);

led2.attach(led2_callback);

Button1.attach(button1_callback);
}

void loop() {
Blinker.run();
}