• UID1571
  • 登录2018-07-20
  • 粉丝5
  • 发帖140
  • 科研点数0点
优异服役勋章
耕耘者十字勋章
zt07elecfreaks 发布于2018-01-10 18:25
0/282

基于Arduino UNO制作一个定时音乐播放器

楼层直达
基于Arduino UNO制作一个定时音乐播放器

简介:
使用Arduino制作一个可以定时播放音乐的设备,定时播放一段音乐,放松心情,有能提醒该做某件事情了。
材料和工具:
1 X Freaduino UNO Rev2.2 MB_EFUNO
1 X Mp3 Module
2 X Octopus Real-time Clock
1 X TF
1 X 音响
硬件连接:

图片:1.jpg




[table=414.8][tr][td=1,1,276][/td][td=1,1,276][/td][/tr][tr][td=1,1,276]
VCC
[/td][td=1,1,276]
V
[/td][/tr][tr][td=1,1,276]
GND
[/td][td=1,1,276]
G
[/td][/tr][tr][td=1,1,276]
TX
[/td][td=1,1,276]
D2
[/td][/tr][tr][td=1,1,276]
RX
[/td][td=1,1,276]
D3
[/td][/tr][/table]
[table=414.8][tr][td=1,1,276][/td][td=1,1,276][/td][/tr][tr][td=1,1,276]
VCC
[/td][td=1,1,276]
V
[/td][/tr][tr][td=1,1,276]
GND
[/td][td=1,1,276]
G
[/td][/tr][tr][td=1,1,276]
SDA
[/td][td=1,1,276]
A4
[/td][/tr][tr][td=1,1,276]
SCL
[/td][td=1,1,276]
A5
[/td][/tr][/table]

图片:2.jpg


MP3 Module inspired from JQ6500-24SS MP3 chipset of Jiaqiang Electronics. It supports SD cards for FAT16, FAT32 file systems and SPI Flash updates via PC. Via some very simple serial commands to control music playback, it owns the characteristics of easy operation and stable performance. Additionally, with an external headphone (PH) and an external speaker (SP), the MP3 Module provides more interfaces and utility.

MP3 Module操作指令如下表所示:

图片:3.jpg


图片:3.jpg




OCTOPUS Real-time Clock is a clock module which can achieve counting for year, month, day, hour by using the DS1307 clock chip.This chip has lots of merits, low power supply, with 56 bytes of non-volatile RAM clock calendar full BCD code real-time clock chip, the address and data via a two-wire bidirectional serial bus transmission, providing seconds, minutes, hours and other information , automatically adjusting the number of days in each month. And more surprisingly, the chip also equip with the function of leap year compensation. Chip has a built-in power-sense circuit, brownout detection, and battery switching function.
代码编程:
首先我们需要加载两个库文件:“DS1307RTC”和“Time

图片:5.jpg








然后点击Examples-DS1307RTC-SetTime”,打开“SetTime”代码,然后上传代码,将电脑的系统时间设置成为Octopus Real-time Clock的内部时间

图片:6.jpg


(插入SetTime代码)

接下来,下载我们定时放歌的代码:
(插入代码)

代码说明
Mp3 Module 的操作指令我们需要以数组的形式写进代码里,通过串口发送这些指令从而实现对Mp3 Module的控制
unsigned char play[6] = {0x7E, 0x04, 0x03, 0x00, 0x01, 0xEF}; //播放 bofang
unsigned char SC_SD[5] = {0x7E, 0x03, 0x09, 0x01, 0xEF};//设置播放音效
unsigned char play_mode[5] = {0x7E, 0x03, 0x11, 0x00, 0xEF};//设置循环方式
unsigned char  pause[4] = {0x7E, 0x02, 0x0E, 0xEF}; //停止tingzhi
unsigned char  next[4] = {0x7E, 0x02, 0x01, 0xEF}; //下一曲

设置软件串口引脚
SoftwareSerial mySerial(2, 3);

设置播放的开始和结束时间,数组里面三个值分别代表:开始的时间的时针,分针,和结束播放的时间分针
unsigned int time1[3] = {9, 0, 5}; //9点0分开始 5分结束

判断时间是否在9点0分到95分之间,如果是则开始播放音乐
if (TimeHour == time1[0] && TimeMinute >= time1[1] && TimeMinute < time1[2]  ) //9点00分
 
  {
 
    if (MP3status == 0)
 
    {
 
      mySerial.write(next, 4);
 
      delay(5);
 
      mySerial.write(play, 6); //开始播放
 
      delay(10);
 
      Serial.println("The first start");
 
      MP3status = 1;
 
    }
 
    else
 
      Serial.println("The first start");
 
  }


判断时间是否是9点5分,如果是则停止播放音乐
if (TimeHour == time1[0] && TimeMinute == time1[2]  )
 
 {
 
   if (MP3status == 1)
 
   {
 
     mySerial.write(pause, 4); //停止播放
 
     delay(10);
 
     Serial.println("The first one is over");
 
     MP3status = 0;
 
   }
 
   else
 
     Serial.println("The first one is over");
 
 }


制作成功

现在你已经成功制作了一个定时音乐播放器。让我们一起来看看效果怎么样吧!

图片:7.JPG


https://www.elecfreaks.com/12128.html
您需要登录后才可以回帖
发表回复

杩斿洖椤堕儴