“音乐播放”的版本间的差异

来自Labplus盛思维基百科
跳转至: 导航搜索
使用教程
第26行: 第26行:
 
== 使用教程 ==
 
== 使用教程 ==
 
串口连接波特率9600bps
 
串口连接波特率9600bps
 +
[http://wiki.labplus.cn/images/2/27/Mp3_KT540BPrj.zip MP3_SoftSerial驱动下载]
 
=== <small>Arduino示例</small> ===
 
=== <small>Arduino示例</small> ===
 
<pre style="color:blue">
 
<pre style="color:blue">
#include <SoftwareSerial.h>
+
 
 
#include "kt540b.h"
 
#include "kt540b.h"
  
uint8_t inBuff[3] = { 0 };
+
Kt540bClass mp3Play(5,6);   //实例化对象,定义pin5为RX,pin6为TX
uint8_t inByte;
 
Kt540bClass mp3Play(5, 6);
 
  
  
 
void setup()
 
void setup()
 
{
 
{
  Serial.begin(115200);
+
mp3Play.begin();       //mp3初始化开始
  mp3Play.begin();
+
mp3Play.setVolume(50);   //音量设置
  mp3Play.setVolume(50);
+
     mp3Play.play(1);         //播放第1首歌曲
     mp3Play.play(1);
+
delay(10000);            //等待,让其播放10秒
 
 
 
}
 
}
  
 
void loop()
 
void loop()
 
{
 
{
  for (uint8_t i = 0; i < 3; i++)
+
mp3Play.pause();         //歌曲暂停
    inBuff[i] = 0;
+
mp3Play.playNext();      //播放下首歌曲
 
+
delay(10000);     //等待,让其播放10秒
  while(Serial.available())
+
mp3Play.stop();        //停止播放歌曲
  {
 
    inByte = Serial.read();
 
    delay(2);
 
    if (inByte == 0xff)
 
    {
 
      inBuff[0] = inByte;
 
      Serial.readBytes(&inBuff[1], 2);
 
    }
 
 
 
    //for (uint8_t i = 0; i < 3; i++)
 
 
 
    //{
 
    //  Serial.write(inBuff[i]);
 
    //}
 
    if (inBuff[1] == 0x01)  // 播放指定歌曲
 
    {
 
      mp3Play.play(inBuff[2]);
 
    }
 
    if (inBuff[1] == 0x02)  // 播放上下首
 
    {
 
      switch (inBuff[2])
 
      {
 
      case 0x01:
 
        mp3Play.playNext();  
 
        break;
 
      case 0x02:
 
        mp3Play.playPrev();
 
        break;
 
      default:
 
        break;
 
       }
 
    }
 
 
 
    if (inBuff[1] == 0x03)  // 设置音量大小
 
    {
 
      mp3Play.setVolume(inBuff[2]);
 
    }
 
 
 
    if (inBuff[1] == 0x04)  // 音量增加减
 
    {
 
      switch (inBuff[2])
 
      {
 
      case 0x01:
 
        mp3Play.volumeInc();
 
         break;
 
      case 0x02:
 
        mp3Play.volumeDec();
 
        break;
 
      default:
 
        break;
 
      }
 
    }
 
  
    if (inBuff[1] == 0x05)  // 暂停、停止播放
 
    {
 
      switch (inBuff[2])
 
      {
 
      case 0x01:
 
        mp3Play.pause();  //暂停
 
        break;
 
      case 0x02:
 
        mp3Play.play();  //恢复播放
 
        break;
 
      case 0x03:
 
        mp3Play.stop();  //停止播放
 
        break;
 
      default:
 
        break;
 
      }
 
    } 
 
  }
 
 
}
 
}
  
 
</pre>
 
</pre>

2018年1月11日 (四) 10:08的版本

黑色传感器最终版12.20-24.png

概述

MP3播放模块,可通串口发送指令操控播放TF卡中保存的歌曲


技术参数

  • 工作电压: VCC 3.3V -5V
  • 串口通信
  • 采用TF卡存储歌曲或语音信息
  • 输出功率3W
  • 板载双声道功放,可驱动0.5W喇叭
  • 模块尺寸:24x46x7.5mm

引脚定义

VCC 电源
RXI 串口接收
TXD 串口发送
GND

使用教程

串口连接波特率9600bps MP3_SoftSerial驱动下载

Arduino示例


#include "kt540b.h"

Kt540bClass mp3Play(5,6);    //实例化对象,定义pin5为RX,pin6为TX


void setup()
{
	mp3Play.begin();        //mp3初始化开始
	mp3Play.setVolume(50);   //音量设置
    mp3Play.play(1);         //播放第1首歌曲
	delay(10000);            //等待,让其播放10秒
}

void loop()
{
	mp3Play.pause();         //歌曲暂停
	mp3Play.playNext();       //播放下首歌曲
	delay(10000);		     //等待,让其播放10秒
	mp3Play.stop();         //停止播放歌曲

}