Colored status led not fully working
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.
- "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.
- 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 ?
- 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
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) {
?
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.
@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.
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)