leds module

The flow3r badge features a background task that helps creating smooth LED transitions. Users who choose to not expose themselves to blinking lights may do so by reducing the maximum slew rate in the system menu. This is the slew rate applications will default to on_enter(). There are rare occassions in which it is necessary for an application to function properly to increase this number, a good example is LED Painter which becomes unusable at too low of a slew rate.

Please consider carefully if you wish to go above the user setting.

import leds
import math
from st3m.ui import colours

def on_enter(self, vm):
    # mellow slew rate but never greater than user value
    leds.set_slew_rate(min(leds.get_slew_rate(), 180))
    leds.set_all_rgba(*colours.hsv_to_rgb(math.tau/3, 1, 1), 0.5)
    leds.update()

def on_enter(self, vm):
    # for response time critical applications like LED Painter: set practical minimum
    leds.set_slew_rate(max(leds.get_slew_rate(), 200))
    leds.set_all_rgba(*colours.hsv_to_rgb(math.tau/3, 1, 1), 0.5)
    leds.update()
leds.set_slew_rate(b: int) None

Set maximum change rate of channel brightness. Set to 255 to disable. Takes the edge off at around 200, mellows things at 150, gets slow at 100, takes its time at 50, molasses at 0. Default 235.

leds.get_slew_rate() int

Get maximum change rate of brightness. See set_slew_rate()

leds.get_steady() bool

Returns true if the LED engine is certain that there is no further color change until user input occurs, meaning that the last animation has finished and there is no unprocessed data is queued up. The LED task consumes data at 50Hz.

If you use this function to time next animation frames be sure to set a maximum rate so that users with a high slew rate setting will not get strobelighted!

leds.set_rgb(i: int, r: float, g: float, b: float) None

Set LED i to rgb value r, g, b

Parameters:
  • i – LED index, from 0 to 39

  • r – Red value, from 0.0 to 1.0

  • g – Green value, from 0.0 to 1.0

  • b – Blue value, from 0.0 to 1.0

leds.get_rgb(i: int) Tuple[float, float, float]

Get rgb tuple of LED i

Parameters:

i – LED index, from 0 to 39

leds.set_all_rgb(r: float, g: float, b: float) None

Set all LEDs to rgb value r, g, b

Parameters:
  • r – Red value, from 0.0 to 1.0

  • g – Green value, from 0.0 to 1.0

  • b – Blue value, from 0.0 to 1.0

leds.set_rgba(ix: int, r: float, g: float, b: float, a: float) None

Set LED i to rgb alpha value r, g, b, a

Parameters:
  • ix – LED index, from 0 to 39

  • r – Red value, from 0.0 to 1.0

  • g – Green value, from 0.0 to 1.0

  • b – Blue value, from 0.0 to 1.0

  • a – Alpha value, from 0.0 to 1.0

leds.set_all_rgba(r: float, g: float, b: float, a: float) None

Set all LEDs to rgb alpha value r, g, b, a

Parameters:
  • r – Red value, from 0.0 to 1.0

  • g – Green value, from 0.0 to 1.0

  • b – Blue value, from 0.0 to 1.0

  • a – Alpha value, from 0.0 to 1.0

leds.update() None

Update LEDs. Ie., copy the LED state from the first buffer into the second buffer, effectively scheduling the LED state to be presented to the user.

leds.set_brightness(b: int) None

Set global LED brightness, 0-255. Default 70.

Only affects the LEDs after update(), or if autoupdate is enabled.

leds.get_brightness() int

Returns global LED brightness, 0-255. Default 70.

leds.set_auto_update(on: bool) None

Make update() be periodically called by the background task for slew rate animation when set to 1. This adds user changes immediately. Useful with low slew rates.

leds.get_auto_update() bool

Returns whether auto updates are on. See set_auto_update()