自己的设置颜色、闪烁函数(会卡在里面)

This commit is contained in:
dgjames 2025-01-17 17:42:05 +08:00
parent 5de7792f95
commit c4bf317bee
3 changed files with 65 additions and 26 deletions

View File

@ -55,6 +55,12 @@ const RGBColor_TypeDef LT_GREEN = {32, 0, 0};
const RGBColor_TypeDef LT_BLUE = {0, 0, 32};
const RGBColor_TypeDef LT_WHITE = {16, 16, 16};
const RGBColor_TypeDef LED_OFF = {0, 0, 0};
const RGBColor_TypeDef LED_ON = {255, 255, 255};
//灯处于特定颜色还是闪烁状态
uint8_t LED_staue[LED_NUM]={0};
// 灯颜色缓存
RGBColor_TypeDef RGB_Data[LED_NUM] = {0};
@ -158,7 +164,34 @@ void Set_LEDColor(uint16_t LedId, RGBColor_TypeDef Color)
RGB_Data[LedId].R = Color.R;
RGB_Data[LedId].B = Color.B;
}
void LED_Set(uint16_t LedId, RGBColor_TypeDef Color)
{
RGB_Data[LedId].G = Color.G;
RGB_Data[LedId].R = Color.R;
RGB_Data[LedId].B = Color.B;
RGB_Reflash();
}
void LED_Toggle(uint16_t LedId, RGBColor_TypeDef Color)
{
while(1)
{
LED_Set(LedId,Color);
rt_thread_mdelay(500);
LED_Set(LedId,LED_OFF);
rt_thread_mdelay(500);
}
}
void LED_LITTLE_TEST(void)
{
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
* @param[in]

View File

@ -15,6 +15,9 @@ extern const RGBColor_TypeDef LED_RED;
extern const RGBColor_TypeDef LED_BLUE;
extern const RGBColor_TypeDef LED_WHITE;
extern void Set_LEDColor(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 RGB_Reflash(void);
extern void LED_LITTLE_TEST(void);
extern void led_matrix_rst();
#endif

View File

@ -439,31 +439,34 @@ void led_matrix_example_entry(void *parameter)
// RGB_Show_64(); // 调用RGB灯板显示函数
// rt_thread_mdelay(500);
// }
int count = 0;
while (1)
{
for (int i = EXTERN_LED_0; i <= EXTERN_LED_18; i++)
{
switch (count)
{
case 0:
Set_LEDColor(i, LED_RED);
break;
case 1:
Set_LEDColor(i, LED_GREEN);
break;
case 2:
Set_LEDColor(i, LED_BLUE);
break;
default:
return;
break;
}
RGB_Reflash();
rt_thread_delay(20);
}
count = (count + 1) % 3;
}
// int count = 0;
// while (1)
// {
// for (int i = EXTERN_LED_0; i <= EXTERN_LED_18; i++)
// {
// switch (count)
// {
// case 0:
// Set_LEDColor(i, LED_RED);
// break;
// case 1:
// Set_LEDColor(i, LED_GREEN);
// break;
// case 2:
// Set_LEDColor(i, LED_BLUE);
// break;
// default:
// return;
// break;
// }
// RGB_Reflash();
// rt_thread_delay(20);
// }
// count = (count + 1) % 3;
// }
LED_LITTLE_TEST();
}
// /* 用于接收消息的信号量 */
// static struct rt_semaphore rx_sem;