Bedtime. /LEDs

LEDs

The four RGB LEDs — driven directly, or through the OS pattern engine

The device has 4 RGB LEDs, indexed 0-3. The OS runs its own animations on them, so stop whatever is playing before you drive them yourself:

os_led_stop_current();               // once, in init()
hal_led_set_rgb(0, 100, 70, 20);     // then from tick()

Patterns versus direct writes

Writing from tick() is the simple route and costs you nothing but the call. For anything that animates on its own clock, hand the OS a led_pattern_t instead: the LED task steps it on its own timer, so the animation keeps running at a steady rate even when your tick() is busy, and it survives a frame you skip.

Note — Nothing restores the OS patterns when your app exits. Put the device back the way you found it in deinit() — either write the LEDs yourself or call os_led_stop_current().

void hal_led_set_rgb(const uint8_t led_num, const uint8_t red, const uint8_t green, const uint8_t blue)

Set one LED's colour

const uint8_tled_numLED index, 0-3
const uint8_tred0-255
const uint8_tgreen0-255
const uint8_tblue0-255

Note — The driver latches: an LED keeps its last written colour until you change it. Nothing restores OS patterns when your app exits, so set the LEDs back or call os_led_stop_current() in deinit().

void os_led_stop_current(void)

Stop the OS LED pattern currently playing

uint8_t os_led_get_step(const os_led_t* led)

Read the step counter from inside a pattern callback

const os_led_t*led
void os_led_set_pattern(led_pattern_t* pattern, const void* ctx)

Start a pattern, replacing whatever is currently playing

led_pattern_t*pattern
const void*ctxwhen non-NULL, overrides the pattern's own ctx for this run

Note — The pattern outlives the call — give it static storage, not a local.