本帖最后由 gimz 于 2017-3-29 15:08 编辑
折腾了几周终于实现了一些基础功能,和大家分享一下。
还山寨了一下倒车警告。
一、配件
01.减速电机和轮子
7ff3df03738da977c35614fbb951f8198718e34d.jpg (84.36 KB, 下载次数: 13)
2017-3-28 16:43 上传
c3605a8da9773912485f17b1f1198618377ae24d.jpg (76.3 KB, 下载次数: 16)
2017-3-28 16:43 上传
02.车架和铜柱
9c141012b31bb051055d21f83f7adab44bede04d.jpg (91.04 KB, 下载次数: 17)
2017-3-28 16:43 上传
46ee80773912b31b4c155ff98f18367adbb4e14d.jpg (101.93 KB, 下载次数: 17)
2017-3-28 16:43 上传
03.其它配件
Mega2560X1
4路电机控制板X1
拆机笔记本喇叭X2
HC-06蓝牙模块X1
9.6V-800mAhX1(主板供电)
9.6V-14400mAhX1(电机外设供电)
86789951f8198618c93e7d5443ed2e738ad4e64d.jpg (70.14 KB, 下载次数: 17)
2017-3-28 16:44 上传
0c719a1bb051f819785c919ad3b44aed2f73e74d.jpg (66.92 KB, 下载次数: 24)
2017-3-28 16:44 上传
cd7aaf18367adab44ba8899382d4b31c8601e44d.jpg (56.62 KB, 下载次数: 23)
2017-3-28 16:44 上传
8532d1198618367adaf1ed0d27738bd4b21ce54d.jpg (53.68 KB, 下载次数: 13)
2017-3-28 16:44 上传
二、代码
初版代码没做简化,后期打算加继电器,做车头大灯、倒车灯、转向灯……
[kenrobot_code]/**
* 日期: 2017/03/28
* 作者: Gimz
* 描述: 初版
*/
/
//前左
const int MA01 = 3 ;
const int MA02 = 4 ;
//前右
const int MB01 = 5 ;
const int MB02 = 6 ;
//后左
const int MC01 = 8 ;
const int MC02 = 9 ;
//后右
const int MD01 = 10 ;
const int MD02 = 11 ;
//定义马达引脚名称
const int Hummer = 2 ;
//定义蜂鸣器引脚名称
const int Spotlight = 12 ;//全车灯
const int Taillight = 13 ;//倒车灯
//定义车灯引脚名称
//const int 继电器 = 7 ;
boolean TaillightState;
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
//定义通讯频率
pinMode(MA01, OUTPUT);
pinMode(MA02, OUTPUT);
pinMode(MB01, OUTPUT);
pinMode(MB02, OUTPUT);
pinMode(MC01, OUTPUT);
pinMode(MC02, OUTPUT);
pinMode(MD01, OUTPUT);
pinMode(MD02, OUTPUT);
//定义马达引脚模式
pinMode(Spotlight, OUTPUT);
digitalWrite(Spotlight, LOW);
pinMode(Taillight, OUTPUT);
digitalWrite(Taillight, LOW);
pinMode(Hummer, OUTPUT);
}
void loop()
{
while (Serial1.available())
//循环检测蓝牙输入信息
{
char C = Serial1.read();
switch (C)
{
//进入循环体,检测蓝牙指令。
//定义前进信号
case'A':
Serial.println("go on");
digitalWrite(MA02, HIGH);
digitalWrite(MB02, HIGH);
digitalWrite(MC02, HIGH);
digitalWrite(MD02, HIGH);
break;
case'E':
Serial.println("go on-stop");
digitalWrite(MA02, LOW);
digitalWrite(MB02, LOW);
digitalWrite(MC02, LOW);
digitalWrite(MD02, LOW);
break;
//前进
//定义后退信号
case'B':
Serial.println("go back");
digitalWrite(Taillight, HIGH);
digitalWrite(MA01, HIGH);
digitalWrite(MB01, HIGH);
digitalWrite(MC01, HIGH);
digitalWrite(MD01, HIGH);
TaillightState = true ;
break;
case'F':
Serial.println("go back-stop");
digitalWrite(MA01, LOW);
digitalWrite(MB01, LOW);
digitalWrite(MC01, LOW);
digitalWrite(MD01, LOW);
digitalWrite(Taillight, LOW);
TaillightState = false;
noTone(Hummer);
break;
//后退
//定义转左信号
case'C':
Serial.println("go left");
digitalWrite(MA01, HIGH);
digitalWrite(MC01, HIGH);
digitalWrite(MB02, HIGH);
digitalWrite(MD02, HIGH);
delay(300);
digitalWrite(MA01, LOW);
digitalWrite(MC01, LOW);
digitalWrite(MB02, LOW);
digitalWrite(MD02, LOW);
break;
//转左
//定义转右信号
case'D':
Serial.println("go right");
digitalWrite(MA02, HIGH);
digitalWrite(MC02, HIGH);
digitalWrite(MB01, HIGH);
digitalWrite(MD01, HIGH);
delay(300);
digitalWrite(MA02, LOW);
digitalWrite(MC02, LOW);
digitalWrite(MB01, LOW);
digitalWrite(MD01, LOW);
break;
//转右
//定义开关车头大灯
case'L':
if (digitalRead (Spotlight) == HIGH)
{
Serial.println("Colse Spotlight");
digitalWrite(Spotlight, LOW);
}
else if (digitalRead (Spotlight) == LOW)
{
Serial.println("Open Spotlight");
digitalWrite(Spotlight, HIGH);
}
break;
//开关车头大灯
//定义喇叭
case'S':
tone(Hummer, 2600, 1000);
delay(500);
noTone(Hummer);
delay(10);
break;
//定义喇叭
default:
break;
}//switch
}//while
if( Taillight && TaillightState )
{
tone(Hummer, 2600, 500);
delay(300);
tone(Hummer, 1600, 500);
delay(300);
}//if
}//loop
bь[/kenrobot_code]
b37b1f7adab44aed2c362c34ba1c8701a08bfb4d.jpg (110.71 KB, 下载次数: 24)
2017-3-28 16:44 上传
0319f3b44aed2e73889114fc8e01a18b86d6fa4d.jpg (44.03 KB, 下载次数: 21)
2017-3-28 16:44 上传
其它内容下次升级版再分享吧。
视频展示:https://v.qq.com/x/page/z0388eym9zk.html