完成闪烁函数(线程)

This commit is contained in:
dgjames 2025-01-17 19:52:53 +08:00
parent c4bf317bee
commit 827d08456c
2 changed files with 48 additions and 18 deletions

View File

@ -59,7 +59,9 @@ const RGBColor_TypeDef LED_OFF = {0, 0, 0};
const RGBColor_TypeDef LED_ON = {255, 255, 255}; const RGBColor_TypeDef LED_ON = {255, 255, 255};
//灯处于特定颜色还是闪烁状态 //灯处于特定颜色还是闪烁状态
uint8_t LED_staue[LED_NUM]={0}; uint8_t LED_Blink_Staue[LED_NUM]={0};
// 灯闪烁颜色缓存
RGBColor_TypeDef LED_Blink_Color[LED_NUM] = {0};
// 灯颜色缓存 // 灯颜色缓存
RGBColor_TypeDef RGB_Data[LED_NUM] = {0}; RGBColor_TypeDef RGB_Data[LED_NUM] = {0};
@ -171,26 +173,48 @@ void LED_Set(uint16_t LedId, RGBColor_TypeDef Color)
RGB_Data[LedId].B = Color.B; RGB_Data[LedId].B = Color.B;
RGB_Reflash(); RGB_Reflash();
} }
void LED_Toggle(uint16_t LedId, RGBColor_TypeDef Color) void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color)
{ {
while(1) LED_Blink_Staue[LedId]=1;
{ LED_Blink_Color[LedId]=Color;
LED_Set(LedId,Color); // while(1)
rt_thread_mdelay(500); // {
LED_Set(LedId,LED_OFF); // LED_Set(LedId,Color);
rt_thread_mdelay(500); // rt_thread_mdelay(500);
} // LED_Set(LedId,LED_OFF);
// rt_thread_mdelay(500);
// }
} }
void LED_LITTLE_TEST(void) void LED_LITTLE_TEST(void)
{ {
LED_Set(1,LED_RED); uint8_t LED_Blink_ON=1;
rt_thread_mdelay(4000); while(1)
LED_Toggle(1,LED_RED); {
rt_thread_mdelay(4000); for(int LedId=0;LedId<LED_NUM;LedId++)
LED_Set(1,LED_RED); {
rt_thread_mdelay(4000); if(LED_Blink_Staue[LedId])
LED_Toggle(1,LED_RED); {
rt_thread_mdelay(4000); if(LED_Blink_ON)
{
Set_LEDColor(LedId,LED_Blink_Color[LedId]);
}
else
{
Set_LEDColor(LedId,LED_OFF);
}
}
}
RGB_Reflash();
rt_thread_mdelay(500);
}
// LED_Set(1,LED_RED);
// rt_thread_mdelay(4000);
// LED_Toggle(1,LED_RED);
// rt_thread_mdelay(4000);
// LED_Set(1,LED_RED);
// rt_thread_mdelay(4000);
// LED_Toggle(1,LED_RED);
// rt_thread_mdelay(4000);
} }
/** /**
* @brief TIM发送控制ws2812 * @brief TIM发送控制ws2812

View File

@ -9,6 +9,12 @@ typedef struct RGBColor_TypeDef
uint8_t B; uint8_t B;
} RGBColor_TypeDef; // 颜色结构体 } RGBColor_TypeDef; // 颜色结构体
// //灯处于特定颜色还是闪烁状态
// extern uint8_t LED_Blink_Staue[LED_NUM]={0};
// // 灯闪烁颜色缓存
// extern RGBColor_TypeDef LED_Blink_Color[LED_NUM] = {0};
extern const RGBColor_TypeDef LED_DARK; extern const RGBColor_TypeDef LED_DARK;
extern const RGBColor_TypeDef LED_GREEN; extern const RGBColor_TypeDef LED_GREEN;
extern const RGBColor_TypeDef LED_RED; extern const RGBColor_TypeDef LED_RED;
@ -16,7 +22,7 @@ extern const RGBColor_TypeDef LED_BLUE;
extern const RGBColor_TypeDef LED_WHITE; extern const RGBColor_TypeDef LED_WHITE;
extern void Set_LEDColor(uint16_t LedId, RGBColor_TypeDef Color); extern void Set_LEDColor(uint16_t LedId, RGBColor_TypeDef Color);
extern void LED_Set(uint16_t LedId, RGBColor_TypeDef Color); extern void LED_Set(uint16_t LedId, RGBColor_TypeDef Color);
extern void LED_Toggle(uint16_t LedId, RGBColor_TypeDef Color); extern void LED_Blink(uint16_t LedId, RGBColor_TypeDef Color);
extern void RGB_Reflash(void); extern void RGB_Reflash(void);
extern void LED_LITTLE_TEST(void); extern void LED_LITTLE_TEST(void);
extern void led_matrix_rst(); extern void led_matrix_rst();