|
两门考试之间有一周的间隔,我和室友想给自己找点事做,一合计干脆就做辆WIFI小车。为了省事儿就直接买了OPENJUMPER的小车套件。
话不多说,直接上图
提一个小建议
在分享设备页面希望能加上不同设备的识别码,没有识别码真的让我在分享的时候一通好找
最后附上代码
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "a5f8552de1d6";
char ssid[] = "Xiaomi_7617";
char pswd[] = "411411*#";
BlinkerButton Button1("forward");
BlinkerButton Button2("left");
BlinkerButton Button3("right");
BlinkerButton Button4("reverse");
BlinkerButton Button5("halt");
//wifiduino开发板接口前要有D
int lmotor_p=D3;//左直流电机
int lmotor_n=D4;
int rmotor_p=D7;//右直流电机
int rmotor_n=D8;
void button1_callback(const String & state1)
{
if(state1=="press")
{
BLINKER_LOG("get button state: ", state1);
digitalWrite(lmotor_p,HIGH);
digitalWrite(lmotor_n,LOW);
digitalWrite(rmotor_p,HIGH);
digitalWrite(rmotor_n,LOW);
Blinker.vibrate();//按键震动
}
else
{
digitalWrite(lmotor_p,LOW);
digitalWrite(lmotor_n,LOW);
digitalWrite(rmotor_p,LOW);
digitalWrite(rmotor_n,LOW);
}
}
void button2_callback(const String & state2)
{
if(state2=="press")
{
BLINKER_LOG("get button state: ", state2);
digitalWrite(lmotor_p,HIGH);
digitalWrite(lmotor_n,LOW);
digitalWrite(lmotor_n,LOW);
digitalWrite(rmotor_p,LOW);
Blinker.vibrate();//按键震动
}
else
{
digitalWrite(lmotor_p,LOW);
digitalWrite(lmotor_n,LOW);
digitalWrite(rmotor_p,LOW);
digitalWrite(rmotor_n,LOW);
}
}
void button3_callback(const String & state3)
{
if(state3=="press")
{
BLINKER_LOG("get button state: ", state3);
digitalWrite(rmotor_p,HIGH);
digitalWrite(rmotor_n,LOW);
digitalWrite(lmotor_p,LOW);
digitalWrite(lmotor_n,LOW);
Blinker.vibrate();//按键震动
}
else
{
digitalWrite(lmotor_p,LOW);
digitalWrite(lmotor_n,LOW);
digitalWrite(rmotor_p,LOW);
digitalWrite(rmotor_n,LOW);
}
}
void button4_callback(const String & state4)
{
if(state4=="press")
{
BLINKER_LOG("get button state: ", state4);
digitalWrite(lmotor_p,LOW);
digitalWrite(lmotor_n,HIGH);
digitalWrite(rmotor_p,LOW);
digitalWrite(rmotor_n,HIGH);
Blinker.vibrate();//按键震动
}
else
{
digitalWrite(lmotor_p,LOW);
digitalWrite(lmotor_n,LOW);
digitalWrite(rmotor_p,LOW);
digitalWrite(rmotor_n,LOW);
}
}
void button5_callback(const String & state5)
{
if(state5=="press")
{
BLINKER_LOG("get button state: ", state5);
digitalWrite(lmotor_p,LOW);
digitalWrite(lmotor_n,LOW);
digitalWrite(rmotor_p,LOW);
digitalWrite(rmotor_n,LOW);
Blinker.vibrate();//按键震动
}
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
Blinker.begin(auth,ssid,pswd);
pinMode(lmotor_p,OUTPUT);
pinMode(lmotor_n,OUTPUT);
pinMode(rmotor_p,OUTPUT);
pinMode(rmotor_n,OUTPUT);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Button4.attach(button4_callback);
Button5.attach(button5_callback);
}
void loop()
{
Blinker.run();
}
|
|