|
感觉像直接一直进入while循环了,开关都失效了
e#define BLINKER_WIFI
#define BLINKER_ESP_SMARTCONFIG
#include <Blinker.h>
char auth[] = "004d8f720f4e";
int n =digitalRead(D9);
// 新建组件对象
BlinkerButton Button1("btn-qian");
BlinkerButton Button2("btn-hou");
BlinkerButton Button3("btn-zuo");
BlinkerButton Button4("btn-you");
BlinkerButton Button5("btn-zuoqian");
BlinkerButton Button6("btn-zuohou");
BlinkerButton Button7("btn-youqian");
BlinkerButton Button8("btn-youhou");
BlinkerButton Button9("btn-zuozhuuan");
BlinkerButton Button10("btn-youzhuan");
BlinkerButton Button11("btn-xunhang");
BlinkerNumber Number1("num-abc");
int counter = 0;
#define ZSQ D1
#define ZSH D2
#define YSQ D3
#define YSH D4
#define ZXQ D5
#define ZXH D6
#define YXQ D7
#define YXH D8
#define TIME_TAP 100
void blinker_car_init()
{
pinMode(ZSQ, OUTPUT);
pinMode(ZSH, OUTPUT);
pinMode(YSQ, OUTPUT);
pinMode(YSH, OUTPUT);
pinMode(ZXQ, OUTPUT);
pinMode(ZXH, OUTPUT);
pinMode(YXQ, OUTPUT);
pinMode(YXH, OUTPUT);
pinMode(D9, INPUT);
digitalWrite(ZSQ, LOW);
digitalWrite(ZSH, LOW);
digitalWrite(YSQ, LOW);
digitalWrite(YSH, LOW);
digitalWrite(ZXQ, LOW);
digitalWrite(ZXH, LOW);
digitalWrite(YXQ, LOW);
digitalWrite(YXH, LOW);
}
// 按下按键即会执行该函数
void button11_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
while(state=="on"){
Button11.print("on");
while(n==LOW && state=="on"){
digitalWrite(ZSQ,HIGH);
digitalWrite(YSH,HIGH);
digitalWrite(ZXQ,HIGH);
digitalWrite(YXH,HIGH);
Blinker.delay(50);
digitalWrite(ZSQ,LOW);
digitalWrite(YSH,LOW);
digitalWrite(ZXQ,LOW);
digitalWrite(YXH,LOW);
}
digitalWrite(ZSQ,HIGH);
digitalWrite(YSQ,HIGH);
digitalWrite(ZXQ,HIGH);
digitalWrite(YXQ,HIGH);
Blinker.delay(50);
digitalWrite(ZSQ,LOW);
digitalWrite(YSH,LOW);
digitalWrite(ZXQ,LOW);
digitalWrite(YXH,LOW);
}
if(state=="off"){
Button11.print("off");
}
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void setup() {
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// 初始化有LED的IO
blinker_car_init();
pinMode(LED_BUILTIN, OUTPUT);
// 初始化blinker
Blinker.begin(auth);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
Button6.attach(button6_callback);
Button7.attach(button7_callback);
Button8.attach(button8_callback);
Button9.attach(button9_callback);
Button10.attach(button10_callback);
Button11.attach(button11_callback);
}
void loop() {
Blinker.run();
}
|
|