LED 闪烁代码
程序员文章站
2024-03-25 12:55:34
...
/*
************************************************************
* 函数名称: Led1_StateRefresh
*
* 函数功能: LED1 闪烁,
*
* 入口参数: ledState:0:不闪烁 ;1:1s闪烁一次 ;2:1s闪烁两次
*
* 返回参数: 无
*
* 说明: 100ms 调用一次,开关间隔100ms
************************************************************
*/
static void Led1_StateRefresh(uint8_t ledState)
{
#define LED_PERIID_TIME 10 // period 1.0s
#define LED_LIGHTING_TIME 1 // lighting last time
#define LED_CYCLE_TIME 1 // one times
static int32_t s_LedCycleTime = LED_PERIID_TIME;
static int32_t s_Cnt = LED_LIGHTING_TIME * LED_CYCLE_TIME * 2;
if(s_LedCycleTime > 0){
s_LedCycleTime --;
if(s_Cnt > 0){
if(s_Cnt % (LED_LIGHTING_TIME * 2) == 0){
Led1_Set(LED_ON);
}else{
Led1_Set(LED_OFF);
}
s_Cnt --;
}else{
Led1_Set(LED_OFF);
}
}else{
s_LedCycleTime = LED_PERIID_TIME;
s_Cnt = LED_LIGHTING_TIME * ledState * 2;
Led1_Set(LED_OFF);
}
}
上一篇: vue添加animate.css动画
下一篇: div 增加闪烁效果