blinker端的数据键名称是与代码对应的,连接wifi特显示arduino在线,但按键的话把8266接到电脑串口监视器没有任何反应 #define BLINKER_PRINT Serial #define BLINKER_MQTT #include <Blinker.h> int x =0; char auth[] = "43c21aaab3fe"; char ssid[] = "ABCDEFG"; char pswd[] = "123456789"; int ComDATA; int i; int shi; int ge; // 新建组件对象 BlinkerButton Button1("zidong"); BlinkerButton Button2("choushui"); BlinkerButton Button3("paishui"); BlinkerButton Button4("tingzhi"); BlinkerText Text1("shuiwei"); BlinkerText Text2("shuiwen"); void ComDATA_PD() { while (Serial.available() ) { char ComDATA = Serial.read(); switch (ComDATA) { case 97://a Text1.print("高"); break; case 98://b Text1.print("中"); break; case 99://c Text1.print("低"); break; default: if(isdigit(ComDATA)){ x=x*10+ComDATA - '0';//i++; if(i==2){i=0;Text2.print("");} } Text2.print(x); break; } }x=0; } int counter = 0; // 按下按键即会执行该函数 void button1_callback(const String & state) { //BLINKER_LOG2("get button state: ", state); Serial.println(1); //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); } void button2_callback(const String & state) { // BLINKER_LOG2("get button state: ", state); Serial.println(2); //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); } void button3_callback(const String & state) { //BLINKER_LOG2("get button state: ", state); Serial.println(3); //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); } void button4_callback(const String & state) { //BLINKER_LOG2("get button state: ", state); Serial.println(4); //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); } void setup() { // 初始化串口 Serial.begin(9600); // 初始化有LED的IO //pinMode(LED_BUILTIN, OUTPUT); //digitalWrite(LED_BUILTIN, HIGH); // 初始化blinker Blinker.begin(auth, ssid, pswd); Button1.attach(button1_callback); Button2.attach(button2_callback); Button3.attach(button3_callback); Button4.attach(button4_callback); } void loop() { Blinker.run(); ComDATA_PD(); // 如果未绑定的组件被触发,则会执行其中内容 /*if (Blinker.available()) { BLINKER_LOG2("Blinker.readString(): ", Blinker.readString()); counter++; Number1.print(counter); }*/ }
|