本帖最后由 辉煌仪奇 于 2018-6-2 17:26 编辑
经过两天的捣鼓,在终于将语音模块给捣鼓出来了,语音模块使用的是MY2490-16P,省钱又多功能的一个模块,好了不多说了下面是MY2490的说明书:http://www.51hei.com/bbs/dpj-83694-1.html
下面是测试程序
#include <SoftwareSerial.h>
#include "yuyin.h"
SoftwareSerial mySerial(2, 3); // RX, TX
String comdata = "";
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
for (int i = 0; i < 24; i++)
Disply_num(i);
}
void Disply_num(int x)//播放音乐函数
{
switch (x)//选择播放哪一首音乐
{
case 0: mySerial.write(num24, 7); break;//0
case 1: mySerial.write(num1, 7); break;//1
case 2: mySerial.write(num2, 7); break;//2
case 3: mySerial.write(num3, 7); break;//3
case 4: mySerial.write(num4, 7); break;//4
case 5: mySerial.write(num5, 7); break;//5
case 6: mySerial.write(num6, 7); break;//6
case 7: mySerial.write(num7, 7); break;//7
case 8: mySerial.write(num8, 7); break;//8
case 9: mySerial.write(num9, 7); break;//9
case 10: mySerial.write(num10, 7); break;
case 11: mySerial.write(num11, 7); break;
case 12: mySerial.write(num12, 7); break;
case 13: mySerial.write(num13, 7); break;
case 14: mySerial.write(num14, 7); break;
case 15: mySerial.write(num15, 7); break;
case 16: mySerial.write(num16, 7); break;
case 17: mySerial.write(num19, 7); break;
case 18: mySerial.write(num20, 7); break;
case 19: mySerial.write(num21, 7); break;
case 20: mySerial.write(num22, 7); break;
case 21: mySerial.write(num23, 7); break;
//case 22: mySerial.write(num25, 7); break;
case 22: mySerial.write(num17, 7); break;
case 23: mySerial.write(num18, 7); break;
// case 25: mySerial.write(num26, 7); break;
}
if (x > 20)
{
comdata = "";//字符串清零
GOTOH:
while (mySerial.available() > 0)
{
comdata += char(mySerial.read());//读取模拟串口数据
delay(1);
}
Serial.println(comdata);
mySerial.flush();
if (comdata == "OKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKOKSTOP" || comdata == "OKSTOP")//判断音乐是否播完
;
else
goto GOTOH;
}
else if (x <= 20 && x > 12)
delay(1200);
else
delay(800);
}
#ifndef YUYIN_H
#define YUYIN_H
#include<arduino.h>
byte num1[7] = {0x7E, 0x05, 0x41, 0x00, 0x01, 0x45, 0xEF}; //1
byte num2[7] = {0x7E, 0x05, 0x41, 0x00, 0x02, 0x46, 0xEF}; //2
byte num3[7] = {0x7E, 0x05, 0x41, 0x00, 0x03, 0x47, 0xEF}; //3
byte num4[7] = {0x7E, 0x05, 0x41, 0x00, 0x04, 0x40, 0xEF}; //4
byte num5[7] = {0x7E, 0x05, 0x41, 0x00, 0x05, 0x41, 0xEF}; //5
byte num6[7] = {0x7E, 0x05, 0x41, 0x00, 0x06, 0x42, 0xEF}; //6
byte num7[7] = {0x7E, 0x05, 0x41, 0x00, 0x07, 0x43, 0xEF}; //7
byte num8[7] = {0x7E, 0x05, 0x41, 0x00, 0x08, 0x4c, 0xEF}; //8
byte num9[7] = {0x7E, 0x05, 0x41, 0x00, 0x09, 0x4d, 0xEF}; //9
byte num10[7] = {0x7E, 0x05, 0x41, 0x00, 0x0a, 0x4e, 0xEF}; //10
byte num11[7] = {0x7E, 0x05, 0x41, 0x00, 0x0b, 0x4f, 0xEF}; //百
byte num12[7] = {0x7E, 0x05, 0x41, 0x00, 0x0c, 0x48, 0xEF}; //点
byte num13[7] = {0x7E, 0x05, 0x41, 0x00, 0x0d, 0x49, 0xEF}; //体重
byte num14[7] = {0x7E, 0x05, 0x41, 0x00, 0x0e, 0x4a, 0xEF}; //千克
byte num15[7] = {0x7E, 0x05, 0x41, 0x00, 0x0f, 0x4b, 0xEF}; //身高
byte num16[7] = {0x7E, 0x05, 0x41, 0x00, 0x10, 0x54, 0xEF}; //厘米
byte num17[7] = {0x7E, 0x05, 0x41, 0x00, 0x11, 0x55, 0xEF}; //欢迎使用
byte num18[7] = {0x7E, 0x05, 0x41, 0x00, 0x12, 0x56, 0xEF}; //欢迎使用,请站好
byte num19[7] = {0x7E, 0x05, 0x41, 0x00, 0x13, 0x57, 0xEF}; //偏胖
byte num20[7] = {0x7E, 0x05, 0x41, 0x00, 0x14, 0x50, 0xEF}; //偏瘦
byte num21[7] = {0x7E, 0x05, 0x41, 0x00, 0x15, 0x51, 0xEF}; //适中
byte num22[7] = {0x7E, 0x05, 0x41, 0x00, 0x16, 0x52, 0xEF}; //建议
byte num23[7] = {0x7E, 0x05, 0x41, 0x00, 0x17, 0x53, 0xEF}; //感谢使用
byte num24[7] = {0x7E, 0x05, 0x41, 0x00, 0x18, 0x5c, 0xEF}; //0
byte num25[7] = {0x7E, 0x05, 0x41, 0x00, 0x19, 0x5d, 0xEF}; //等待超时感谢使用
byte num26[7] = {0x7E, 0x05, 0x41, 0x00, 0x1a, 0x5e, 0xEF}; //JuLy——In Love
#endif
将程序下载进板子以后将语音模块的TX RX于3,2号引脚相连接连上电源喇叭就可以正常放歌了,到此时语音模块正式于完成。
|