|
#include <dummy.h>
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "a186fe825165";
char ssid[] = "OPPOr17";
char pswd[] = "12345678";
// 新建组件对象
BlinkerButton Button1("btn-a"); //前进
BlinkerButton Button2("btn-rr"); //后退
BlinkerButton Button3("btn-l"); //左转
BlinkerButton Button4("btn-r"); //右转
int counter = 0;
#define IN1 4
#define IN2 16
#define IN3 17
#define IN4 5
#define TIME_TAP 100
void blinker_car_init()
{
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
// 前进
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if(state=="tap"){
digitalWrite(IN1,HIGH);
digitalWrite(IN3,HIGH);
delay(TIME_TAP);
digitalWrite(IN1,LOW);
digitalWrite(IN3,LOW);
}
if(state=="press"){
digitalWrite(IN1,HIGH);
digitalWrite(IN3,HIGH);
}
if(state=="pressup"){
digitalWrite(IN1,LOW);
digitalWrite(IN3,LOW);
}
}
//后退
void button2_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if(state=="tap"){
digitalWrite(IN2,HIGH);
digitalWrite(IN4,HIGH);
delay(TIME_TAP);
digitalWrite(IN2,LOW);
digitalWrite(IN4,LOW);
}
if(state=="press"){
digitalWrite(IN2,HIGH);
digitalWrite(IN4,HIGH);
}
if(state=="pressup"){
digitalWrite(IN2,LOW);
digitalWrite(IN4,LOW);
}
}
//左转
void button3_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if(state=="tap"){
digitalWrite(IN2,HIGH);
delay(TIME_TAP);
digitalWrite(IN2,LOW);
}
if(state=="press"){
digitalWrite(IN2,HIGH);
}
if(state=="pressup"){
digitalWrite(IN2,LOW);
}
}
//右转
void button4_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if(state=="tap"){
digitalWrite(IN4,HIGH);
delay(TIME_TAP);
digitalWrite(IN4,LOW);
}
if(state=="press"){
digitalWrite(IN4,HIGH);
}
if(state=="pressup"){
digitalWrite(IN4,LOW);
}
}
// 如果未绑定的组件被触发,则会执行其中内容
/*void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
*/
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);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
}
void loop() {
Blinker.run();
}
网上借鉴修改的程序一直报错
|
|