0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

【RTT大賽作品連載】AB32VG1評(píng)估板 炫酷音樂(lè)播放器

磐石90 ? 來(lái)源:磐石90 ? 作者:磐石90 ? 2021-11-26 08:43 ? 次閱讀

之前,記錄了從新建項(xiàng)目到點(diǎn)燈,按鈕控制彩燈測(cè)試,再到如何AB32VG1評(píng)估板實(shí)現(xiàn)音樂(lè)播放器!今天通過(guò)對(duì)前邊的經(jīng)驗(yàn)提煉!實(shí)現(xiàn)炫酷音樂(lè)播放器?。?!

硬件如圖:

image.png

因用到彩燈需短接J8,J10,J12,TF卡需短接P2的對(duì)應(yīng)pin!

應(yīng)用RT-Thread Studio IDE,可快速實(shí)現(xiàn)對(duì)組件包的配置!

image.png

軟件實(shí)現(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);
}

}

}
音樂(lè)播放控制用到了兩個(gè)線程。一個(gè)通過(guò)按鈕事件線程控制音樂(lè)播放!一個(gè)通過(guò)音樂(lè)播放狀態(tài)來(lái)檢測(cè)是否切換歌曲,避免播放一首之后,因無(wú)按鈕操作而停止!

按鈕事件線程:

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);
}
}
}

音樂(lè)播放狀態(tài)來(lái)檢測(cè)線程:

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);}
}

}
}
}
通過(guò)以上主要的線程,在加上前面的【RTT大賽作品連載】AB32VG1評(píng)估板到貨控制彩燈測(cè)試-電子發(fā)燒友網(wǎng) (elecfans.com)的部分代碼即可實(shí)現(xiàn)炫酷音樂(lè)播放器!

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • RTOS
    +關(guān)注

    關(guān)注

    20

    文章

    804

    瀏覽量

    119117
  • 開發(fā)板
    +關(guān)注

    關(guān)注

    25

    文章

    4771

    瀏覽量

    96187
  • 代碼
    +關(guān)注

    關(guān)注

    30

    文章

    4671

    瀏覽量

    67770
  • RT-Thread
    +關(guān)注

    關(guān)注

    31

    文章

    1239

    瀏覽量

    39441
  • 中科藍(lán)訊
    +關(guān)注

    關(guān)注

    9

    文章

    52

    瀏覽量

    9799
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    RTT大賽作品連載AB32VG1開箱、搭建環(huán)境、演示、點(diǎn)燈

    AB32VG1】開箱、搭建環(huán)境、演示、點(diǎn)燈,為下面做好準(zhǔn)備。
    的頭像 發(fā)表于 10-25 16:47 ?4909次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】<b class='flag-5'>AB32VG1</b>開箱、搭建環(huán)境、演示、點(diǎn)燈

    RTT大賽作品連載AB32VG1上手

    AB32VG1上手操作,修改例程運(yùn)行中的問(wèn)題,成功點(diǎn)亮RGB。
    的頭像 發(fā)表于 10-28 18:31 ?7593次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】 <b class='flag-5'>AB32VG1</b>上手

    RTT大賽作品連載AB32VG1評(píng)估到貨點(diǎn)燈測(cè)試

    AB32VG1評(píng)估到貨點(diǎn)燈測(cè)試.
    的頭像 發(fā)表于 11-04 08:55 ?7624次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】<b class='flag-5'>AB32VG1</b><b class='flag-5'>評(píng)估</b><b class='flag-5'>板</b>到貨點(diǎn)燈測(cè)試

    RTT大賽作品AB32VG1開發(fā)OLED顯示實(shí)驗(yàn)

    最近在玩AB32VG1,在做OLED顯示實(shí)驗(yàn)時(shí),很多關(guān)于AB32VG1驅(qū)動(dòng)OLED的文章,很多都是官方例程操作,在msh窗口中輸入測(cè)試指令,測(cè)試驅(qū)動(dòng)是否正常。很少有關(guān)于在main函數(shù)中直接實(shí)現(xiàn)的,本編文章直接在MAIN函數(shù)實(shí)現(xiàn)OLED顯示,上電自動(dòng)執(zhí)行。
    的頭像 發(fā)表于 11-05 16:03 ?6089次閱讀
    <b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b>:<b class='flag-5'>AB32VG1</b>開發(fā)<b class='flag-5'>板</b>OLED顯示實(shí)驗(yàn)

    RTT大賽作品AB32VG1開發(fā)—按鍵掃描

    ab32vg1開發(fā)按鍵實(shí)驗(yàn)
    的頭像 發(fā)表于 11-15 09:54 ?4058次閱讀
    <b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b>:<b class='flag-5'>AB32VG1</b>開發(fā)<b class='flag-5'>板</b>—按鍵掃描

    RTT大賽作品連載AB32VG1評(píng)估到貨控制彩燈測(cè)試

    RTT大賽作品連載AB32VG1評(píng)估到貨控制彩
    的頭像 發(fā)表于 11-07 19:39 ?5068次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】<b class='flag-5'>AB32VG1</b><b class='flag-5'>評(píng)估</b><b class='flag-5'>板</b>到貨控制彩燈測(cè)試

    RTT大賽作品連載AB32VG1評(píng)估 音樂(lè)播放器

    RTT大賽作品連載AB32VG1評(píng)估
    的頭像 發(fā)表于 11-12 21:11 ?6108次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】<b class='flag-5'>AB32VG1</b><b class='flag-5'>評(píng)估</b><b class='flag-5'>板</b> <b class='flag-5'>音樂(lè)</b><b class='flag-5'>播放器</b>

    RTT大賽作品連載】中科藍(lán)訊AB32VG1開發(fā)開箱篇

    介紹電路原理圖分析接口說(shuō)明,AB32VG1開發(fā)是以中科藍(lán)訊(Bluetrum)公司推出的基于RISC-V架構(gòu)的高配置芯片AB5301A為核心所組成的。【RTT
    的頭像 發(fā)表于 11-13 10:01 ?1w次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】中科藍(lán)訊<b class='flag-5'>AB32VG1</b>開發(fā)<b class='flag-5'>板</b>開箱篇

    RTT大賽作品連載AB32VG1的開發(fā)環(huán)境搭建

    基于RT-Thread的AB32VG1開發(fā)環(huán)境搭建.
    的頭像 發(fā)表于 11-17 08:48 ?9275次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】<b class='flag-5'>AB32VG1</b>的開發(fā)環(huán)境搭建

    RTT大賽作品連載AB32VG1開發(fā)之開箱篇

    中科藍(lán)訊AB32VG1開發(fā)的開箱之作,此開發(fā)的硬件資源初略的介紹。
    的頭像 發(fā)表于 01-04 09:19 ?4423次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】<b class='flag-5'>AB32VG1</b>開發(fā)<b class='flag-5'>板</b>之開箱篇

    【RT-Thread設(shè)計(jì)大賽】基于AB32VG1的嵌入式網(wǎng)盤

    【RT-Thread設(shè)計(jì)大賽】基于AB32VG1的嵌入式移動(dòng)網(wǎng)盤
    的頭像 發(fā)表于 07-30 12:12 ?2099次閱讀
    【RT-Thread設(shè)計(jì)<b class='flag-5'>大賽</b>】基于<b class='flag-5'>AB32VG1</b>的嵌入式網(wǎng)盤

    【文章連載】RT-Thread創(chuàng)新應(yīng)用大賽文章匯總

    作品連載AB32VG1評(píng)估到貨點(diǎn)燈測(cè)試專欄作者:辛?xí)鴤?【RT-Thread創(chuàng)新應(yīng)用設(shè)計(jì)大賽
    發(fā)表于 10-11 15:13

    RTT大賽作品連載】中科藍(lán)訊AB32VG1開發(fā)開箱篇

    收到開發(fā)先上靚照中科藍(lán)訊AB32VG1開發(fā)開箱AB32VG1開發(fā)一塊TypeCo數(shù)據(jù)線一條開發(fā)
    發(fā)表于 11-24 08:00

    RTT大賽作品連載】基于AB32VG1 sdk BLE例程

    RT-Thread基本中科藍(lán)訊AB32VG1 BLE開發(fā)快捷方便.
    的頭像 發(fā)表于 12-06 09:07 ?4840次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】基于<b class='flag-5'>AB32VG1</b> sdk BLE例程

    RTT大賽作品連載】linkboy面向AB32V移植(1

    初步移植linkboy到AB32VG1開發(fā)并測(cè)試GPIO輸出
    發(fā)表于 12-18 20:00 ?1162次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】linkboy面向<b class='flag-5'>AB</b>32V移植(<b class='flag-5'>1</b>)