想用blinker按键控制舵机来控制方向,自己写的下面的程序,BLINKER设置单个按键的时候舵机可以控制转动一个角度,但是在加上一个按键的时候只能有一个按键起作用,另一个按键没反应 这是错在哪里了?
#define BLINKER_WIFI
#include <Servo.h>
#include <Blinker.h>
Servo s1;
char auth[] = "53d7";
char ssid[] = "";
char pswd[] = "qy88";
// 新建组件对象
BlinkerButton Button1("btn-1");
BlinkerButton Button2("btn-abc");
BlinkerButton Button3("a");
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(14, !digitalRead(14));
Blinker.vibrate();
}
void button2_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(D6, !digitalRead(13));
Blinker.vibrate();
}
void button3_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(D3, !digitalRead(D3));
Blinker.vibrate();
}
void setup() {
// 初始化串口,并开启调试信息
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// 初始化有LED的IO
pinMode(14, OUTPUT);
pinMode(D6, OUTPUT);
digitalWrite(14, LOW);
digitalWrite(D6, LOW);
pinMode(D3, OUTPUT);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
s1.attach(D3);
}
void loop() {
int Val=digitalRead(D6);
if (Val ==HIGH) {
s1.write(180);
int Va2=digitalRead(14);
if(Va2==LOW){s1.write(135);}
else {
s1.write(90); }
Blinker.run();
}
|