之前,記錄了從新建項目到點燈,按鈕控制彩燈測試,再到如何AB32VG1評估板實現(xiàn)音樂播放器!今天通過對前邊的經(jīng)驗提煉!實現(xiàn)炫酷音樂播放器?。。?/span>
硬件如圖:
因用到彩燈需短接J8,J10,J12,TF卡需短接P2的對應pin!
應用RT-Thread Studio IDE,可快速實現(xiàn)對組件包的配置!
軟件實現(xiàn)
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);
}
}
}
音樂播放控制用到了兩個線程。一個通過按鈕事件線程控制音樂播放!一個通過音樂播放狀態(tài)來檢測是否切換歌曲,避免播放一首之后,因無按鈕操作而停止!
按鈕事件線程:
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);
}
}
}
音樂播放狀態(tài)來檢測線程:
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);}
}
}
}
}
通過以上主要的線程,在加上前面的【RTT大賽作品連載】AB32VG1評估板到貨控制彩燈測試-電子發(fā)燒友網(wǎng) (elecfans.com)的部分代碼即可實現(xiàn)炫酷音樂播放器!
-
RTOS
+關(guān)注
關(guān)注
22文章
819瀏覽量
119890 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5121瀏覽量
98218 -
代碼
+關(guān)注
關(guān)注
30文章
4828瀏覽量
69063 -
RT-Thread
+關(guān)注
關(guān)注
31文章
1305瀏覽量
40391 -
中科藍訊
+關(guān)注
關(guān)注
9文章
57瀏覽量
9933
發(fā)布評論請先 登錄
相關(guān)推薦
評論