更新日期:2019-11-19
按键输入例程
本例程的主要功能是让板载的 KEY1 控制 RGB-LED 中绿色 LED 的亮灭
#include <rtthread.h> #include <rtdevice.h> #include "board.h" #define DBG_TAG "main" #define DBG_LVL DBG_LOG #include <rtdbg.h> int main(void) { unsigned int count = 1; /* 设置 PIN_LED_G 引脚为输出模式 */ rt_pin_mode(PIN_LED_G,PIN_MODE_OUTPUT); /* 设置 PIN_KEY1 引脚为输入模式 */ rt_pin_mode(PIN_KEY1,PIN_MODE_INPUT); while (count > 0) { /* 读取 PIN_KEY1 引脚的状态 */ if(rt_pin_read(PIN_KEY1) == PIN_LOW) { rt_thread_mdelay(50); if(rt_pin_read(PIN_KEY1) == PIN_LOW) { LOG_D("KEY1 pressed!"); rt_pin_write(PIN_LED_G, PIN_LOW); } } else { rt_pin_write(PIN_LED_G, PIN_HIGH); } rt_thread_mdelay(10); count++; } return 0; } |
实物照片: