流程图



硬件

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 避障报距小车的更多相关文章

  1. 具有避障和寻线功能的Arduino小车

    标签:  Arduino  乐高  机器人 创客对于成年人来说,多半是科技娱乐,或者是一种是一种向往科技的人生态度,总是希望自己不仅可以看到或者听到科技的资讯,还希望能够亲身制作科技玩意,从而更好地体 ...

  2. 【雕爷学编程】Arduino动手做(45)---红外避障传感器

    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里 ...

  3. [TPYBoard - Micropython 之会python就能做硬件 9] 五分种学会用TPYBoard V102 制作避障小车(升级版)

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 感谢山东萝卜电子科技公司授权   一.实验器材 1.TPYboard V102板 ...

  4. 智能循迹避障小车&抢答器

    智能循迹避障小车 →视频链接← 抢答器

  5. [TPYBoard - Micropython之会python就能做硬件 8] 学习使用超声波模块制作避障小车

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604   一.实验器材 1.TPYboard V102板  一块 2.电机驱动模块L2 ...

  6. SLAM+语音机器人DIY系列:(六)SLAM建图与自主避障导航——2.google-cartographer机器人SLAM建图

    摘要 通过前面的基础学习,本章进入最为激动的机器人自主导航的学习.在前面的学习铺垫后,终于迎来了最大乐趣的时刻,就是赋予我们的miiboo机器人能自由行走的生命.本章将围绕机器人SLAM建图.导航避障 ...

  7. win7下Arduino Mega 2560驱动安装失败解决办法

    因为玩四轴用的apm的飞控板,而其需要安装此驱动,曾经在win8使用其,但是因为win8有相对应的数字证书保护措施(应该是这样的,因为好久了记不清楚了),以至于我每次都需要长按shift重启电脑关闭此 ...

  8. Bug避障算法简介

    移动机器人智能的一个重要标志就是自主导航,而实现机器人自主导航有个基本要求--避障.避障是指移动机器人根据采集的障碍物的状态信息,在行走过程中通过传感器感知到妨碍其通行的静态和动态物体时,按照一定的方 ...

  9. 机器人局部避障的动态窗口法(dynamic window approach) (转)

    源:机器人局部避障的动态窗口法(dynamic window approach) 首先在V_m∩V_d的范围内采样速度: allowable_v = generateWindow(robotV, ro ...

随机推荐

  1. String的intern()方法详解

    https://blog.csdn.net/soonfly/article/details/70147205  :图解 https://blog.csdn.net/wjzhang5514/articl ...

  2. linux解压缩命令之unzip,tar(持续更新)

    unzip apache-tomcat-7.0.78.zip -d /usr/local/src/ 解压zip压缩包到/usr/local/src,-d就是指定解压路径的意思

  3. Centos7 下安装配置tomcat7

    首先下载压缩包 wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.78/bin/apache-tomcat-7. ...

  4. C# to IL 5 Operator Overloading(操作符重载)

    Every operator overload that we use in C#, gets converted to a function call in IL. Theoverloaded &g ...

  5. Tower Defense Toolkit 学习

    代码太多,就不贴了.用到的基本已注释. 游戏中的数据存放在Resources/Database中.游戏运行时,通过Resources.Load加载 UI构成   对象池 using UnityEngi ...

  6. 修改VS2017模板文件,添加文件头部自定义注释

    找到Class.cs文件 找到VS2017安装目录下面的Class.cs文件,一般在C盘或者D盘 模块文件位置: 接口模版:C:\Program Files (x86)\Microsoft Visua ...

  7. AspNet Core Api Restful +Swagger 发布IIS

    上一步我们创建好CoreApi 接下来在框架中加入 Swagger  并发布  到 IIS (1)首先点击依赖项>管理Nuget包 (2)输入 Swashbuckle.aspnetCore  比 ...

  8. STM32的ISP下载程序方式:

    STM32的板子的串口ISP下载方法:Boot0接到3.3V上,Boot1接到GND,对板子重新上电,STM32单片机重启的时候,会进入到ISP模式.

  9. MySQL事务描述

    并发事务处理引起的数据问题 更新丢失(Lost Update):当两个或多个事务选择同一行,然后基于最初选定的值更新该行时,由于每个事务都不知道其他事务的存在,就会发生丢失更新问题--最后的更新覆盖了 ...

  10. MySQL 遇到错误集锦

    MySQL 规定:varchar必须指定长度,否则报错:ERROR 1064 (42000) 只有一列时,primary key 直接写在这一列的后面: 没有定义主键时,提示错误:ERROR 1075 ...