上次發(fā)布了一篇文章(【RTT大賽作品連載】AB32VG1評(píng)估板到貨點(diǎn)燈測(cè)試-電子發(fā)燒友網(wǎng) (elecfans.com)),解決很多愛好者從在RT-ThreadStudio新建項(xiàng)目到對(duì)應(yīng)開發(fā)配置及下載等各部分環(huán)節(jié)的問題!得到了很多愛好者的認(rèn)可!

哈哈,先曬點(diǎn)贊的!

重要的是幫好多愛好者解決了實(shí)際問題!
接下來看看在如何AB32VG1評(píng)估板控制彩燈!
在RT-ThreadStudio新建項(xiàng)目到對(duì)應(yīng)開發(fā)配置及下載及驗(yàn)證測(cè)試!!!
還是詳細(xì)點(diǎn)!!!用截圖-》
新建項(xiàng)目!


點(diǎn)完成,新建就好了!
接下來是這次會(huì)用的軟件包設(shè)置!!!

設(shè)置好后點(diǎn)關(guān)閉,會(huì)提示保存設(shè)置選項(xiàng),點(diǎn)保存即可!
接下來會(huì)用到這幾IO!如圖

軟件代碼內(nèi)容暫時(shí)直接寫在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'更好玩,喜歡的愛好者可以試試讓它更炫酷!!!
最后,看到上一篇閱讀量破2100了(【RTT大賽作品連載】AB32VG1評(píng)估板到貨點(diǎn)燈測(cè)試-電子發(fā)燒友網(wǎng) (elecfans.com))
很高興!!!大家一起加油!!!
-
led
+關(guān)注
關(guān)注
242文章
23741瀏覽量
671347 -
RTOS
+關(guān)注
關(guān)注
24文章
844瀏覽量
120817 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5563瀏覽量
102688 -
RT-Thread
+關(guān)注
關(guān)注
32文章
1372瀏覽量
41556 -
中科藍(lán)訊
+關(guān)注
關(guān)注
9文章
59瀏覽量
10161
發(fā)布評(píng)論請(qǐng)先 登錄
新品 | 用于CoolSiC? MOSFET FF6MR20W2M1H_B70的雙脈沖測(cè)試評(píng)估板

Analog Devices Inc. EVAL-ADRF5714 評(píng)估板數(shù)據(jù)手冊(cè)

Analog Devices Inc. EVAL-ADRF5715 評(píng)估板數(shù)據(jù)手冊(cè)

(大賽作品)STM32F072RB NUCLEO智能家居控制實(shí)例項(xiàng)目
Analog Devices Inc. EV-ADF4030SD1Z評(píng)估板數(shù)據(jù)手冊(cè)


ADS1285EVM-PDK評(píng)估板輸出沒有動(dòng)態(tài)信號(hào),只有靜態(tài)信號(hào)是怎么回事?
【干貨】性價(jià)比拉滿!HK32F407VG開發(fā)板介紹

機(jī)智云ESP8266開發(fā)板RGB彩燈控件

評(píng)論