docs/modules/ws2812-effects.md
| Since | Origin / Contributor | Maintainer | Source |
|---|---|---|---|
| 2017-11-01 | Konrad Huebner | Konrad Huebner | ws2812_effects.c |
This module provides effects based on the WS2812 library. Some effects are inspired by / based on the WS2812FX Library but have been adopted to the specifics of the ws2812 library. The effects library works based on a buffer created through the ws2812 library and performs the operations on this buffer.
Note that dual mode is currently not supported for effects.
!!! caution
This module is deprecated and will be removed in favor of a generic,
in-Lua implementation soon. (Sooner with help!) Please see
https://github.com/nodemcu/nodemcu-firmware/issues/3122 .
!!! caution
This module depends on the [color utils module](color-utils.md) and [pixbuf module](pixbuf.md). Things **will** fail if those modules are missing in the firmware!
-- init the ws2812 module
ws2812.init(ws2812.MODE_SINGLE)
-- create a buffer, 60 LEDs with 3 color bytes
strip_buffer = ws2812.newBuffer(60, 3)
-- init the effects module, set color to red and start blinking
ws2812_effects.init(strip_buffer)
ws2812_effects.set_speed(100)
ws2812_effects.set_brightness(50)
ws2812_effects.set_color(0,255,0)
ws2812_effects.set_mode("blink")
ws2812_effects.start()
Initialize the effects library with the provided buffer for the connected LED strip.
ws2812_effects.init(buffer)
buffer is a ws2812.buffer for the connected strip.nil
Start the animation effect.
ws2812_effects.start()
none
nil
Stop the animation effect.
ws2812_effects.stop()
none
nil
Set the brightness.
ws2812_effects.set_brightness(brightness)
brightness brightness between 0 and 255nil
Set the color.
ws2812_effects.set_color(g, r, b, [w])
g is the green value between 0 and 255r is the red value between 0 and 255b is the blue value between 0 and 255w (optional) is the white value between 0 and 255nil
Set the speed.
ws2812_effects.set_speed(speed)
speed speed between 0 and 255nil
Get current speed.
ws2812_effects.get_speed()
none
speed between 0 and 255
Set the delay between two effect steps in milliseconds.
ws2812_effects.set_delay(delay)
delay is the delay in milliseconds, minimum 10msnil
Get current delay.
ws2812_effects.get_delay()
none
delay is the current effect delay in milliseconds
Set the active effect mode.
ws2812_effects.set_mode(mode, [effect_param])
mode is the effect mode as a string, can be one of
static fills the buffer with the color set through ws2812_effects.set_color()blink fills the buffer with the color set through ws2812_effects.set_color() and starts blinkinggradient fills the buffer with a gradient defined by the color values provided with the effect_param. This parameter must be a string containing the color values with same pixel size as the current buffer configuration. Minimum two colors must be provided. If more are provided, the strip is split in equal parts and the colors are used as intermediate colors. The gradient is calculated based on HSV color space, so no greyscale colors are supported as those cannot be converted to HSV.gradient_rgb similar to gradient but uses simple RGB value interpolation instead of conversions to the HSV color space.random_color fills the buffer completely with a random color and changes this color constantlyrainbow animates through the full color spectrum, with the entire strip having the same colorrainbow_cycle fills the buffer with a rainbow gradient. The optional second parameter states the number of repetitions (integer).flicker fills the buffer with the color set through ws2812_effects.set_color() and begins random flickering of pixels with a maximum flicker amount defined by the second parameter (integer, e.g. 50 to flicker with 50/255 of the color)fire is a fire flickering effectfire_soft is a soft fire flickering effectfire_intense is an intense fire flickering effecthalloween fills the strip with purple and orange pixels and circles themcircus_combustus fills the strip with red/white/black pixels and circles themlarson_scanner is the K.I.T.T. scanner effect, based on the color set through ws2812_effects.set_color()color_wipe fills the strip pixel by pixel with the color set through ws2812_effects.set_color() and then starts turning pixels off again from beginning to end.random_dot sets random dots to the color set through ws2812_effects.set_color() and fades them out againcycle takes the buffer as-is and cycles it. With the second parameter it can be defined how many pixels the shift will be. Negative values shift to opposite direction.effect_param is an optional effect parameter. See the effect modes for further explanations. It can be an integer value or a string.nil
Full initialization code for the strip, a buffer and the effect library can be found at top of this documentation. Only effect examples are shown here.
-- rainbow cycle with two repetitions
ws2812_effects.set_mode("rainbow_cycle", 2)
-- gradient from red to yellow to red
ws2812_effects.set_mode("gradient", string.char(0,200,0,200,200,0,0,200,0))
-- random dots with fading
ws2812_effects.set_mode("random_dot",3)