【RTT大赛作品连载】AB32VG1评估板到货控制彩灯测试

描述

上次发布了一篇文章(【RTT大赛作品连载】AB32VG1评估板到货点灯测试-电子发烧友网 (elecfans.com)),解决很多爱好者从在RT-ThreadStudio新建项目到对应开发配置及下载等各部分环节的问题!得到了很多爱好者的认可!

RTOS

哈哈,先晒点赞的!

RTOS

 

重要的是帮好多爱好者解决了实际问题!

接下来看看在如何AB32VG1评估板控制彩灯!

在RT-ThreadStudio新建项目到对应开发配置及下载及验证测试!!!

还是详细点!!!用截图-》

新建项目!

RTOS


RTOS

点完成,新建就好了!

接下来是这次会用的软件包设置!!!

RTOS

设置好后点关闭,会提示保存设置选项,点保存即可!

接下来会用到这几IO!如图

RTOS

软件代码内容暂时直接写在main函数文件里!!!

如图

具体内容如下:

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

编译好,下载验证如下!

RTOS

验证OK!

其实还可以在此基础上,让ColorLed'更好玩,喜欢的爱好者可以试试让它更炫酷!!!

最后,看到上一篇阅读量破2100了(【RTT大赛作品连载】AB32VG1评估板到货点灯测试-电子发烧友网 (elecfans.com))

很高兴!!!大家一起加油!!!

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分