This driver provides a generic base class for driving WS2812-based LED strips. This is not a plugin, and is not meant to be user-facing. It is meant to be used by developers, and hardware plugins in particular. See the KBDFans KBD4x plugin for a practical, existing example about how to use the driver.
Using the driver¶
To use the driver, we need to include the header:
For performance reasons, the driver is templated, and requires three template arguments:
pin, the PIN the driver will use to communicate with the LED strip.
class Color, the color class that determines the order of the RGB components, and should match the component order the LED strip uses. We provide three orders out of the box, all in the
ledCountis the number of LEDs on the strip this instance of the driver should be able to address.
Armed with this knowledge, instantiating an object is as easy as:
using Color = kaleidoscope::driver::led::color::GRB; kaleidoscope::driver::led::WS2812<PIN_E2, Color, 6> LEDs;
WS2812 object will have the following methods:
Returns the number of LEDs, the same value as the
Synchronises the internal LED state with the hardware, by sending over all of the LED data.
It is recommended to call this at most once per cycle. Calling it less frequently isn’t wrong either.
.setColorAt(index, r, g, b)¶
Sets the color at the given
indexto the specified value. He value can either be a
Colorobject (the same type as the template argument), or a list of RGB component values.
Returns the color at the given
index, as a
To have a better idea how to use the driver in practice, looking at the KBD4x hardware library is recommended.