arduino mega 避障报距小车
流程图
硬件
mega2560
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
#include<string.h>
//变量IO口定义
int a;
int a1=-1;
int a2=-1;
int a3=-1;
char a11;
char a22;
char a33;
int out13 = 13;
int in12 = 12;
int out1 = 11;
int out2 = 10;
int out3 = 9;
int out4 = 8;
int echo = 7;
int trig = 6;
int in1 = 5;
int in2 = 4;
int busy = 3;//喇叭状态
// the setup routine runs once when you press reset:
//启动 定义引脚输入输出
void setup() {
// initialize the digital pin as an output.
pinMode(out1, OUTPUT);
pinMode(out2, OUTPUT);
pinMode(out3, OUTPUT);
pinMode(out4, OUTPUT);
pinMode(in1, INPUT);
pinMode(in2, INPUT);
pinMode(in12, INPUT);
pinMode(out13, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(busy,INPUT); //初始化串口
do Serial3.begin(9600);while(!Serial3);
Serial.begin(9600); //置 0
}
/*
超声波模块
*/
int chaoshengbo(){
unsigned long time = 0;
int time2 = 0;
digitalWrite(trig, LOW);
delay(1);
digitalWrite(trig, HIGH);
delayMicroseconds(20);
digitalWrite(trig, LOW);
time = pulseIn(echo,HIGH);
time2 = time/58;
// Serial.println(time/58);
delay(300);
return time2;
}
/*
文本转语音模块
*/
void laba() {
int err=0;
int i=0;
if(a>=100)a11=0x30+a1;
a22=0x30+a2;
a33=0x30+a3;
char data[] = {0xc7,0xb0,0xb7,0xbd,a11,a22,a33,0xc0,0xe5,0xc3,0xd7};
char tou[] = {0xFD,0x00,0x1f,0x01,0x00};
tou[2] = 3+sizeof(data);
for(i=0;i<sizeof(tou);i++) {
Serial3.write(tou[i]);
err^=tou[i];
}
for(i= 0;i<sizeof(data);i++) {
Serial3.write(data[i]);
err^=data[i];
}
Serial3.write(err);
Serial.println(Serial3.read());
}
/*
左转语音
*/
void laba1() {
int err=0;
int i=0;
char data[] = {0xD7,0xF3,0xD7,0xAA};
char tou[] = {0xFD,0x00,0x1f,0x01,0x00};
tou[2] = 3+sizeof(data);
for(i=0;i<sizeof(tou);i++) {
Serial3.write(tou[i]);
err^=tou[i];
}
for(i= 0;i<sizeof(data);i++) {
Serial3.write(data[i]);
err^=data[i];
}
Serial3.write(err);
Serial.println(Serial3.read());
}
/*
右转语音
*/
void laba2() {
int err=0;
int i=0;
char data[] = {0xD3,0xD2,0xD7,0xAA};
char tou[] = {0xFD,0x00,0x1f,0x01,0x00};
tou[2] = 3+sizeof(data);
for(i=0;i<sizeof(tou);i++) {
Serial3.write(tou[i]);
err^=tou[i];
}
for(i= 0;i<sizeof(data);i++) {
Serial3.write(data[i]);
err^=data[i];
}
Serial3.write(err);
Serial.println(Serial3.read());
}
/*
循环执行功能
*/
// the loop routine runs over and over again forever:
void loop() {
//Serial.println(time);
static int b,c = 0;
a = chaoshengbo();
a1=a/100;
if(a<100)a2=a/10;
else a2=a%100/10;
a3=a%10;
// Serial.println(a);
if(a<=15.00) {c++;}
else {c=0;}
// Serial.println(c);
if(2==c) {
c=0;
digitalWrite(out1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(out2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(out3, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(out4, HIGH); // turn the LED off by making the voltage LOW
delay(1000);
}
if( digitalRead(busy)==0 ) laba();
digitalWrite(out1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(out2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(out3, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(out4, LOW); // turn the LED off by making the voltage LOW
digitalWrite(out1, HIGH);//you cuo wu
while(digitalRead(in1)==0) {
laba2();
while(digitalRead(in1)==0) {
digitalWrite(out1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(out2, LOW); // turn the LED off by making the voltage LOW
digitalWrite(out3, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(out4, HIGH); // turn the LED off by making the voltage LOW
}
digitalWrite(out2, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(out1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(out4, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(out3, LOW); // turn the LED off by making the voltage LOW
}
while(digitalRead(in2)==0) {
laba1();
while(digitalRead(in2)==0) {
digitalWrite(out2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(out1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(out4, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(out3, HIGH); // turn the LED off by making the voltage LOW
}
digitalWrite(out2, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(out1, LOW); // turn the LED off by making the voltage LOW
digitalWrite(out4, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(out3, LOW); // turn the LED off by making the voltage LOW
}
}
arduino mega 避障报距小车的更多相关文章
- 具有避障和寻线功能的Arduino小车
标签: Arduino 乐高 机器人 创客对于成年人来说,多半是科技娱乐,或者是一种是一种向往科技的人生态度,总是希望自己不仅可以看到或者听到科技的资讯,还希望能够亲身制作科技玩意,从而更好地体 ...
- 【雕爷学编程】Arduino动手做(45)---红外避障传感器
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里 ...
- [TPYBoard - Micropython 之会python就能做硬件 9] 五分种学会用TPYBoard V102 制作避障小车(升级版)
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 感谢山东萝卜电子科技公司授权 一.实验器材 1.TPYboard V102板 ...
- 智能循迹避障小车&抢答器
智能循迹避障小车 →视频链接← 抢答器
- [TPYBoard - Micropython之会python就能做硬件 8] 学习使用超声波模块制作避障小车
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.实验器材 1.TPYboard V102板 一块 2.电机驱动模块L2 ...
- SLAM+语音机器人DIY系列:(六)SLAM建图与自主避障导航——2.google-cartographer机器人SLAM建图
摘要 通过前面的基础学习,本章进入最为激动的机器人自主导航的学习.在前面的学习铺垫后,终于迎来了最大乐趣的时刻,就是赋予我们的miiboo机器人能自由行走的生命.本章将围绕机器人SLAM建图.导航避障 ...
- win7下Arduino Mega 2560驱动安装失败解决办法
因为玩四轴用的apm的飞控板,而其需要安装此驱动,曾经在win8使用其,但是因为win8有相对应的数字证书保护措施(应该是这样的,因为好久了记不清楚了),以至于我每次都需要长按shift重启电脑关闭此 ...
- Bug避障算法简介
移动机器人智能的一个重要标志就是自主导航,而实现机器人自主导航有个基本要求--避障.避障是指移动机器人根据采集的障碍物的状态信息,在行走过程中通过传感器感知到妨碍其通行的静态和动态物体时,按照一定的方 ...
- 机器人局部避障的动态窗口法(dynamic window approach) (转)
源:机器人局部避障的动态窗口法(dynamic window approach) 首先在V_m∩V_d的范围内采样速度: allowable_v = generateWindow(robotV, ro ...
随机推荐
- Echarts全解注释
coordinate-geo.js文件为地理坐标系的配置参数 mytextStyle={ color:"#333",//文字颜色 fontStyle:"normal&qu ...
- Go Example--关闭通道
package main import ( "fmt" ) func main() { jobs := make(chan int, 5) done := make(chan bo ...
- LG4238 【【模板】多项式求逆】
前言 学习了Great_Influence的递推实现,我给大家说一下多项式求逆严格的边界条件,因为我发现改动一些很小的边界条件都会使程序出错.怎么办,背代码吗?背代码是不可能,这辈子都不会背代码的.理 ...
- 开机或者安装系统时提示tsc: Fast TSC calibration failed解决方法
其实这个问题很简单,主要是时间不对的问题. 就拿我遇到这个问题来说.我是在vm虚拟机中安装了xenserver,然后在物理机安装xencenter连接xenserver,然后在安装新的虚拟机时遇到这个 ...
- 数学的语言 化无形为可见 (Keith Devlin 著)
第一章 数字为何靠的住 (已看) 第二章 心智的模式 (已看) 第三章 动静有数 (已看) 第四章 当数学成型 (已看) 第五章 数学揭开美之本质 (已看) 第六章 当数学到位 (已看) 第七章 数学 ...
- 数学与猜想 合情推理模式 (G. 波利亚 著)
第十二章 几个著名模式 (已看) $1. 证实一个结论 $2. 连续证实几个结论 $3. 证实一个未必可信的结论 $4. 类比推理 $5. 加深类比 $6. 被隐没的类比推理 第十三章 更多的模式与最 ...
- [转]web.xml中<url-pattern>详解
标签<url-pattern><url-pattern>是我们用Servlet做Web项目时需要经常配置的标签,例: <servlet> <servlet-n ...
- 错误:php70w-common conflicts with php-common-5.3.3-49.el6.i686
记录一下 由于之前系统自带的php5.3.3没有卸载干净: 在执行phpize时报错说需要php-devel 然后yum -y install php-delel ; 然后就报错 错误:php70w ...
- checkbox复选框,如何让其勾选时触发一个事件,取消勾选时不触发
<input type="checkbox" onclick="checkboxOnclick(this)" /> <script> f ...
- Myeclipse 配置Git详解
Myeclipse+Git EGit安装 MyEclipse已经集成了Git插件EGit,在window->Preference里搜索git可以看到. 如果没有,安装方式为Help-> ...