pico-sdk icon indicating copy to clipboard operation
pico-sdk copied to clipboard

Colored status led not fully working

Open tazounet opened this issue 4 months ago • 4 comments

Hello,

I was using the code from "pio/ws2812" without problems and then I switch to the new "colored status led" library with the sdk 2.2.0.

  1. "colored_status_led_set_on_with_color" don't change the color if the LED is already ON. Why not but it's not describe in the documentation.
  2. I created a "colored_status_led_change_color" function to handle color change, but it was not working until I add a sleep between "colored_status_led_set_state" and "colored_status_led_set_on_with_color". This timing constraint is not in the documentation. Is it a bug ?
  3. Adding a "colored_status_led_change_color" directly in the library could be a good addition :)

The working code:

bool colored_status_led_change_color(uint32_t color)
{
    colored_status_led_set_state(false);
    sleep_us(100);
    return colored_status_led_set_on_with_color(color);
}

Thanks

tazounet avatar Aug 17 '25 14:08 tazounet

Rather than adding a new colored_status_led_change_color function, does the original code work as expected if you change https://github.com/raspberrypi/pico-sdk/blob/develop/src/rp2_common/pico_status_led/status_led.c#L83 from

        if (led_on && !colored_status_led_on) {

to

        if (led_on) {

?

lurch avatar Aug 17 '25 21:08 lurch

I think you need a delay after setting a ws2812 led (50us?). I'm not sure I like the idea of the API doing this. So setting the led color while it's already on might not work. We could document this however.

peterharperuk avatar Aug 18 '25 09:08 peterharperuk

@lurch yes with this modification we can change the color without the need to set the LED off.

@peterharperuk 50us was not working, 100us seems reliable.

tazounet avatar Aug 18 '25 14:08 tazounet

colored_status_led_set_on_with_color() should change the color; that is its intent; if it doesn't that is a bug.

it is also a requirement of the library to take care of this, as the way the LED behaves is its own problem.

Note that, a different PIO program or implementation could fix this (e.g. if the PIO program continually updated the color with the required delay)

kilograham avatar Aug 18 '25 16:08 kilograham