流程图
硬件
mega2560
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
#include
//变量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