SmartLED – control of WS2812 LEDs

Some boards can control at most one WS2812 LED, and some boards can control a strip of WS2812 LEDs. The former ones have a built-in module signal_led, the latter ones have a built-in module multi_led. The following code can be used to detect which one is supported:

try:
        from multi_led import SignalLED, SmartLED
except ImportError:
        from signal_led import SignalLED, SmartLED

Both modules contain two classes - the SignalLED class and the SmartLED class.

The SmartLED class stores pixel data for a single WS2812 LED (or a WS2812 LED strip) connected to a pin. The SignalLED class controls a single WS2812 LED with a fixed color.

The differences between the corresponding classes from the two modules are outlined below.

class SmartLED

Both classes have the same methods with the same signatures (with the sole exception of the led() method), however for objects of type SmartLED the __setitem and the __getitem methods will work only with the index 0, the fill method is identical to the set method.

class SignalLED

  • The constructor of the multi_led version requires the index argument.

  • The multi_led version does not support the effects, the signal_led version does.

Implementations: