From 1723613b4ece614b80fd7f94c22fce1a20ba6740 Mon Sep 17 00:00:00 2001 From: Ming Kuang Date: Sun, 9 Feb 2025 15:35:42 +0800 Subject: [PATCH] Limit the frequency of LED status updates Unrestricted refreshing of the LED status may cause the WS2812 controller to not work properly. Observed on my waveshare_rp2040_one board where the LED remains either constantly on or off, even though the workflow should dim or turn off/on the LED. --- src/led/led.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/led/led.c b/src/led/led.c index 2bd4040..3b58c9a 100644 --- a/src/led/led.c +++ b/src/led/led.c @@ -39,6 +39,7 @@ void led_blinking_task() { #ifndef ENABLE_EMULATION static uint32_t start_ms = 0; static uint32_t stop_ms = 0; + static uint32_t last_led_update_ms = 0; static uint8_t led_state = false; uint8_t state = led_state; #ifdef PICO_DEFAULT_LED_PIN_INVERTED @@ -62,7 +63,11 @@ void led_blinking_task() { progress = 1; } - led_driver_color(led_color, led_brightness, progress); + // limit the frequency of LED status updates + if (board_millis() - last_led_update_ms > 2) { + led_driver_color(led_color, led_brightness, progress); + last_led_update_ms = board_millis(); + } if (board_millis() >= stop_ms){ start_ms = stop_ms;