和室友没事做的WIFI小车-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2108|回复: 0

和室友没事做的WIFI小车

[复制链接]
发表于 2019-12-28 10:07 | 显示全部楼层 |阅读模式
两门考试之间有一周的间隔,我和室友想给自己找点事做,一合计干脆就做辆WIFI小车。为了省事儿就直接买了OPENJUMPER的小车套件。
话不多说,直接上图
图片1.png


Screenshot_2019-12-28-09-23-39-366_iot.clz.me.jpg

提一个小建议
在分享设备页面希望能加上不同设备的识别码,没有识别码真的让我在分享的时候一通好找
Screenshot_2019-12-28-10-04-37-316_iot.clz.me.jpg

最后附上代码
#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();
}






您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 06:40 , Processed in 0.101842 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表