“音乐播放”的版本间的差异
来自Labplus盛思维基百科
Tangliufeng(讨论 | 贡献) (→技术参数) |
Tangliufeng(讨论 | 贡献) (→使用教程) |
||
第25行: | 第25行: | ||
== 使用教程 == | == 使用教程 == | ||
+ | 串口连接波特率115200bps | ||
=== <small>Arduino示例</small> === | === <small>Arduino示例</small> === | ||
<pre style="color:blue"> | <pre style="color:blue"> |
2018年1月8日 (一) 15:12的版本
概述
MP3播放模块,可通串口发送指令操控播放TF卡中保存的歌曲
技术参数
- 工作电压: VCC 3.3V -5V
- 串口通信
- 采用TF卡存储歌曲或语音信息
- 输出功率3W
- 板载双声道功放,可驱动0.5W喇叭
- 模块尺寸:24x46x7.5mm
引脚定义
VCC | 电源 |
RXI | 串口接收 |
TXD | 串口发送 |
GND | 地 |
使用教程
串口连接波特率115200bps
Arduino示例
#include <SoftwareSerial.h> #include "kt540b.h" uint8_t inBuff[3] = { 0 }; uint8_t inByte; Kt540bClass mp3Play(5, 6); void setup() { Serial.begin(115200); mp3Play.begin(); mp3Play.setVolume(50); mp3Play.play(1); } void loop() { for (uint8_t i = 0; i < 3; i++) inBuff[i] = 0; while(Serial.available()) { 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; } } } }