Addressable LEDs in Berry~
Requires #define USE_WS2812
, included in Tasmota32
Support for addressable leds strips or matrix, including animation. Internally relies on NeoPixelBus library and currently supports WS2812 and SK6812.
How to use~
Compatibility with Templates~
You can control multiple LED strips. WS2812 - 1
is also controlled by Tasmota's light controls. It is still possible to control this light strip with Berry, but whenever you use Tasmota light controls they will temporarily overrid Berry animations.
To avoid any conflict between native WS2812 and Berry control, you can use Scheme 14
which disables native WS2812.
Led strips, matrix and sub-strips~
You first need to define the low-level Leds
object that describes the hardware strip of connected leds.
You can then define higher level objects like sub-strips (if there are actually several strips chained together like rings) or LED matrix.
Once a Leds
object, you can use sub-objects:
LED model | Details |
---|---|
Leds.WS2812_GRB | WS2812b Leds (GRB) - takes 24 bits RGB colors |
Leds.SK6812_GRBW | SK6812 Leds (GRBW) - takes 32 bits RGBW colors (with white channel) |
Methods are the equivalent low-level from NeoPixelBus. All colors are in 0xRRGGBB
format (24 bits) or 0xWWRRGGBB
format (32 bits).
Animation framework~
The class Leds_animator
sets the necessary methods to facilitate animations. You just need create a sub-class or Leds_animator
, provide a Leds
or Leds_matrix
instance and implement the animate
method. You can also register animators
(see below).
The instance is automatically registered as driver. Call start()
to start the animation, and stop()
to stop it.
Example:
import animate
class Rainbow_stripes : Leds_animator
var cur_offset # current offset in the palette
static palette = [ 0xFF0000, #- red -#
0xFFA500, #- orange -#
0xFFFF00, #- yellow -#
0x008800, #- green -#
0x0000FF, #- blue -#
0x4B0082, #- indigo -#
0xEE82EE, #- violet -#
]
# duration in seconds
def init(strip, duration)
super(self).init(strip)
self.cur_offset = 0
# add an animator to change `self.cur_offset` to each value of the palette
self.add_anim(animate.rotate(def(v) self.cur_offset = v end, 0, size(self.palette), int(duration * 1000)))
end
def animate()
var i = 0
while i < self.pixel_count # doing a loop rather than a `for` prevents from allocating a new object
var col = self.palette[(self.cur_offset + i) % size(self.palette)]
self.strip.set_pixel_color(i, col, self.bri) # simulate the method call without GETMET
i += 1
end
self.strip.show()
end
end
How to use:
var strip = Leds(5,5, gpio.pin(gpio.WS2812, 1))
var r = Rainbow_stripes(strip, 1.0)
r.start()
And here is another example that "breathes" the LED strip with a hardcoded colour:
class Breathe : Leds_animator
var brightness
var colour
# duration in seconds
def init(strip, duration)
super(self).init(strip)
self.brightness = 0
self.colour = 0xFFFFFF
self.add_anim(animate.back_forth(def(v) self.brightness = v end, 0, 100, int(duration * 1000)))
end
def animate()
var i = 0
while i < self.pixel_count # doing a loop rather than a `for` prevents from allocating a new object
self.strip.set_pixel_color(i, self.colour, self.brightness)
i += 1
end
self.strip.show()
end
end
And to use this one:
var strip = Leds(5,5, gpio.pin(gpio.WS2812, 1))
var r = Breathe(strip, 2.0)
r.start()
Advanced features~
Hardware RMT
channels~
This library uses NeoPixelBus library, and RMT
hardware support in ESP32. The number of RMT
channels, hence the number of simultaneous strips, depends on the CPU type. Tasmota native support for WS2812 uses RMT
channel 0; it is not usable in such case.
CPU type | RMT channels |
---|---|
ESP32 | 8 |
ESP32S2 | 4 |
ESP32C3 | 2 |
Currently RMT
channel 0 is used by default if no GPIO WS2812-1
is configured, RMT
channel 1 otherwise.