上次發(fā)布了一篇文章(【RTT大賽作品連載】AB32VG1評估板到貨點(diǎn)燈測試-電子發(fā)燒友網(wǎng) (elecfans.com)),解決很多愛好者從在RT-ThreadStudio新建項(xiàng)目到對應(yīng)開發(fā)配置及下載等各部分環(huán)節(jié)的問題!得到了很多愛好者的認(rèn)可!
哈哈,先曬點(diǎn)贊的!
重要的是幫好多愛好者解決了實(shí)際問題!
接下來看看在如何AB32VG1評估板控制彩燈!
在RT-ThreadStudio新建項(xiàng)目到對應(yīng)開發(fā)配置及下載及驗(yàn)證測試!?。?/p>
還是詳細(xì)點(diǎn)?。。∮媒貓D-》
新建項(xiàng)目!
點(diǎn)完成,新建就好了!
接下來是這次會用的軟件包設(shè)置?。?!
設(shè)置好后點(diǎn)關(guān)閉,會提示保存設(shè)置選項(xiàng),點(diǎn)保存即可!
接下來會用到這幾IO!如圖
軟件代碼內(nèi)容暫時直接寫在main函數(shù)文件里?。?!
如圖
具體內(nèi)容如下:
#include
#include "board.h"
#include
#define BUTTON_PIN_0 rt_pin_get("PF.0")//control timeDelay
#define BUTTON_PIN_1 rt_pin_get("PF.1")//control colorLed mode
uint32_t delayTime = 1;
uint32_t state = 0;
uint32_t cnt_0 = 1;
static struct button btn_0;
static struct button btn_1;
static uint8_t button_read_pin_0(void)
{
return rt_pin_read(BUTTON_PIN_0);
}
static uint8_t button_read_pin_1(void)
{
return rt_pin_read(BUTTON_PIN_1);
}
static void button_0_callback(void* btn)
{
uint32_t btn_event_val;
btn_event_val = get_button_event((struct button*)btn);
switch (btn_event_val)
{
case SINGLE_CLICK:
cnt_0++;
delayTime = cnt_0 * 200;
if (cnt_0 == 10)
{
cnt_0 = 1;
}
rt_kprintf("button 0 single click\ndelayTime=%d\n", delayTime);
break;
case DOUBLE_CLICK:
if (cnt_0 > 1)
{
cnt_0--;
}
delayTime = cnt_0 * 200;
rt_kprintf("button 0 double click\ndelayTime=%d\n", delayTime);
break;
case LONG_PRESS_START:
rt_kprintf("button 0 long press start\n");
break;
case LONG_PRESS_HOLD:
rt_kprintf("button 0 long press hold\n");
break;
}
}
static void button_1_callback(void* btn)
{
uint32_t btn_event_val;
btn_event_val = get_button_event((struct button*)btn);
switch (btn_event_val)
{
case SINGLE_CLICK:
state = !state;
if (state == 0) {
rt_kprintf("one color\n");
}
else {
rt_kprintf("more color\n");
}
rt_kprintf("button 1 single click\n");
break;
case DOUBLE_CLICK:
rt_kprintf("more color\n");
rt_kprintf("button 1 single click\n");
default:
break;
}
}
static void btn_thread_entry(void* p)
{
while (1)
{
/* 5ms */
rt_thread_delay(RT_TICK_PER_SECOND / 200);
button_ticks();
}
}
static int multi_button_test(void)
{
rt_thread_t thread = RT_NULL;
/* Create background ticks thread */
thread = rt_thread_create("btn", btn_thread_entry, RT_NULL, 1024, 10, 10);
if (thread == RT_NULL)
{
return RT_ERROR;
}
rt_thread_startup(thread);
/* low level drive */
rt_pin_mode(BUTTON_PIN_0, PIN_MODE_INPUT_PULLUP);
button_init(&btn_0, button_read_pin_0, PIN_LOW);
button_attach(&btn_0, SINGLE_CLICK, button_0_callback);
button_attach(&btn_0, DOUBLE_CLICK, button_0_callback);
button_attach(&btn_0, LONG_PRESS_START, button_0_callback);
button_attach(&btn_0, LONG_PRESS_HOLD, button_0_callback);
button_start(&btn_0);
rt_pin_mode(BUTTON_PIN_1, PIN_MODE_INPUT_PULLUP);
button_init(&btn_1, button_read_pin_1, PIN_LOW);
button_attach(&btn_1, SINGLE_CLICK, button_1_callback);
button_attach(&btn_1, DOUBLE_CLICK, button_1_callback);
button_attach(&btn_1, LONG_PRESS_START, button_1_callback);
button_attach(&btn_1, LONG_PRESS_HOLD, button_1_callback);
button_start(&btn_1);
return RT_EOK;
}
INIT_APP_EXPORT(multi_button_test);
int main(void)
{
uint32_t cnt = 0;
rt_kprintf("Hello, world11\n");
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)
{
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);
}
if (state == 1)
cnt++;
rt_thread_mdelay(delayTime);
}
}
編譯好,下載驗(yàn)證如下!
驗(yàn)證OK!
其實(shí)還可以在此基礎(chǔ)上,讓ColorLed'更好玩,喜歡的愛好者可以試試讓它更炫酷?。。?/p>
最后,看到上一篇閱讀量破2100了(【RTT大賽作品連載】AB32VG1評估板到貨點(diǎn)燈測試-電子發(fā)燒友網(wǎng) (elecfans.com))
很高興?。。〈蠹乙黄鸺佑停。?!
-
led
+關(guān)注
關(guān)注
242文章
23286瀏覽量
661109 -
RTOS
+關(guān)注
關(guān)注
22文章
814瀏覽量
119677 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5059瀏覽量
97549 -
RT-Thread
+關(guān)注
關(guān)注
31文章
1291瀏覽量
40176 -
中科藍(lán)訊
+關(guān)注
關(guān)注
9文章
57瀏覽量
9889
發(fā)布評論請先 登錄
相關(guān)推薦
評論