led控制

led:核心代码讲解

/*
uint8_t led_index,led编号 #define RGB_PIN {LED_R,LED_G,LED_B} 这个一致,0为LED_R 1---LED_G
uint16_t on_ms,一个周期内亮的时间
uint16_t off_ms,一个周期内灭的时间
uint16_t times,周期数
使用实例:led_ctrl(LED_B_INDEX,100,300,10);蓝灯闪烁10次,每次亮100ms灭300ms
*/
void led_ctrl(uint8_t led_index,uint16_t on_ms,uint16_t off_ms,uint16_t times)

调用方法:

init_led_timer:开机调用一次
led_timer_manage放主循环最快速度扫描
led_ctrl需要灯闪烁的时候调用

.h文件

#define LED_NUMBERS   3
#define KEY_PIN 23
#define LED_R 26
#define LED_G 25
#define LED_B 27
#define RGB_PIN  {LED_R,LED_G,LED_B}
#define LED_TIMER  {1,2,4}
#define RGB_LED_ON(A) nrf_gpio_pin_write(A,1)
#define RGB_LED_OFF(A) nrf_gpio_pin_write(A,0)
#define RGB_LED_TOG(A) nrf_gpio_pin_toggle(A)

#define LED_R_INDEX 0
#define LED_G_INDEX 1
#define LED_B_INDEX 2

.c文件

//===========================================

#define LED_NUMBERS   3
static uint8_t time_id=0;
static uint16_t timer_inter_ms=50;

static uint16_t led_on_ms[LED_NUMBERS], led_off_ms[LED_NUMBERS],led_times[LED_NUMBERS];
static uint8_t led_stat[LED_NUMBERS],led_timer_tick[LED_NUMBERS];
static void led_timer_timeout(void * p_context)
{
    uint8_t  i;
    for(i=0;i

你可能感兴趣的:(led控制)