聚丰项目 > 炫酷音乐播放器作品

炫酷音乐播放器作品

RT-Thread Studio IDE 设置AB32VG1支持的相关组件包,实现对TF卡里的指定文件夹的文件遍历,并播放选中的.wav文件,彩灯根据播放状态不同的显示不同的颜色!项目用到的硬件有AB32VG1 的2.0版的开发板,TF卡,美标3.5mm耳机

磐石11 磐石11

分享
3 喜欢这个项目
团队介绍

磐石11 磐石11

团队成员

磐石11 工程师

分享
项目简介
RT-Thread Studio IDE 设置AB32VG1支持的相关组件包,实现对TF卡里的指定文件夹的文件遍历,并播放选中的.wav文件,彩灯根据播放状态不同的显示不同的颜色!项目用到的硬件有AB32VG1 的2.0版的开发板,TF卡,美标3.5mm耳机
硬件说明

申请到是AB32VG1的2.0的开发板!

image.png

因用到彩灯需短接J8,J10,J12,TF卡需短接P2的对应pin,

软件说明

应用RT-Thread Studio IDE,可快速实现对组件包的配置!

image.png

软件实现

led 彩灯的线程如下:

static void led_thread_entry(void* p)
{
uint32_t cnt = 0;
uint8_t pin = rt_pin_get("PE.1");
rt_pin_mode(pin, PIN_MODE_OUTPUT);
uint8_t pin1 = rt_pin_get("PE.4");
rt_pin_mode(pin1, PIN_MODE_OUTPUT);
uint8_t pin2 = rt_pin_get("PA.1");
rt_pin_mode(pin2, PIN_MODE_OUTPUT);

while (1)
{ rt_err_t result = rt_mutex_take(mutex1, 6);
if (result == RT_EOK) {
state = wavplayer_state_get();
rt_mutex_release(mutex1);
if (state== PLAYER_STATE_PLAYING) {
if (cnt % 8 == 0)
{
rt_pin_write(pin, PIN_LOW);
rt_pin_write(pin1, PIN_HIGH);
rt_pin_write(pin2, PIN_HIGH);
}
if (cnt % 8 == 1)
{
rt_pin_write(pin, PIN_HIGH);
rt_pin_write(pin1, PIN_LOW);
rt_pin_write(pin2, PIN_HIGH);
}
if (cnt % 8 == 2)
{
rt_pin_write(pin, PIN_HIGH);
rt_pin_write(pin1, PIN_HIGH);
rt_pin_write(pin2, PIN_LOW);
}
if (cnt % 8 == 3)
{
rt_pin_write(pin, PIN_LOW);
rt_pin_write(pin1, PIN_LOW);
rt_pin_write(pin2, PIN_HIGH);
}
if (cnt % 8 == 4)
{
rt_pin_write(pin, PIN_HIGH);
rt_pin_write(pin1, PIN_LOW);
rt_pin_write(pin2, PIN_LOW);
}
if (cnt % 8 == 5)
{
rt_pin_write(pin, PIN_LOW);
rt_pin_write(pin1, PIN_HIGH);
rt_pin_write(pin2, PIN_LOW);
}
if (cnt % 8 == 6)
{
rt_pin_write(pin, PIN_LOW);
rt_pin_write(pin1, PIN_LOW);
rt_pin_write(pin2, PIN_LOW);
}
if (cnt % 8 == 7)
{
rt_pin_write(pin, PIN_HIGH);
rt_pin_write(pin1, PIN_HIGH);
rt_pin_write(pin2, PIN_HIGH);
}
cnt++;
}else if (state== PLAYER_STATE_PAUSED) {
rt_pin_write(pin, PIN_LOW);
rt_pin_write(pin1, PIN_HIGH);
rt_pin_write(pin2, PIN_HIGH);
rt_thread_mdelay(400);
rt_pin_write(pin, PIN_LOW);
rt_pin_write(pin1, PIN_HIGH);
rt_pin_write(pin2, PIN_LOW);
rt_thread_mdelay(200);
}
else {
rt_pin_write(pin, PIN_LOW);
rt_thread_mdelay(500);
rt_pin_write(pin, PIN_HIGH);
rt_thread_mdelay(500);
}
rt_thread_mdelay(200);
}

}

}
音乐播放控制用到了两个线程。一个通过按钮事件线程控制音乐播放!一个通过音乐播放状态来检测是否切换歌曲,避免播放一首之后,因无按钮操作而停止!

按钮事件线程:

static void btn_thread_entry(void* p)
{
while (1)
{
rt_thread_delay(RT_TICK_PER_SECOND / 500);
rt_err_t result = rt_mutex_take(mutex1, 6);
if (result == RT_EOK) {
button_ticks();
rt_mutex_release(mutex1);
}
}
}

音乐播放状态来检测线程:

static void endCheck_thread_entry(void* p)
{
while (1)
{
rt_thread_mdelay(2500);
rt_err_t result = rt_mutex_take(mutex1, 2);
if (result == RT_EOK) {
state = wavplayer_state_get();
rt_mutex_release(mutex1);
if (state == PLAYER_STATE_STOPED) {
EndState = 0;
rt_thread_mdelay(1000);
result = rt_mutex_take(mutex1, 2);
if (result == RT_EOK) {
state = wavplayer_state_get();
if ((state == PLAYER_STATE_STOPED)&& (EndState == 0)) {
EndState = 1;
if (currentSong == NUM_OF_SONGS) {
currentSong = 0;
}
GetCurrentPath();
wavplayer_play(table);
currentSong++;
}
rt_mutex_release(mutex1);}
}

}
}
}

具体情况请参考源码

演示效果
附件

(8.44 MB)下载

评论区(2 )
  • 磐石11: 加油

    回复

  • jf_61952251: 厉害

    回复