Skip to content

Addressable LEDs in Berry~

Requires #define USE_WS2812, included in Tasmota32

Support for addressable leds strips and animation. Internally relies on optimized TasmotaLED library, currently supporting WS2812 and SK6812, 3 and 4 channels, over RMT and SPI.

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, 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).

Class Details
Leds Leds(pixels:int, gpio:int [,model:int ,rmt:int]) -> instance<Leds>
Creates a Leds instance for a linear leds strip
pixels: number of leds
gpio: physical gpio number
model: (optional) LED model, default: Leds.WS2812_GRB, alternative Leds.SK6812_GRBW
rmt: (optional) RMTchannel to use, or auto-select (see below)

Once a Leds object, you can use sub-objects:

Method Details
create_segment <strip>.create_segment(offset:int, pixels:int) -> instance<Leds_segment>
Creates a virtual segment from a physical Leds strip, from Led number offset with pixels leds.

The Leds_segment class provides the same interface as the Leds class, with the following differences: - It doesn't have its own buffer, it's a view into the parent strip's buffer - The show() method takes an optional force parameter that, when true, forces a show even if the segment doesn't cover the entire strip - The pixels_buffer() method returns nil since segments don't have their own buffer

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).

Attributes Details
clear clear() -> nil
Clear all led (set to black)
clear_to clear_to(col:color [, bri:int]) -> nil
Set all leds to the specified color. bri (0..255) is optional and default to 255
show show() -> nil
Pushes the internal buffer to leds. May be ignored if a show command is already in progress. Use can_show() to see if show() is possible
can_show can_show() -> bool
Indicates if show() is possible, i.e. no transfer is ongoing
can_show_wait can_show_wait() -> nil
Waits until show() is possible, i.e. no transfer is ongoing
is_dirty is_dirty() -> bool
Indicates if a led was changed since last show()
dirty dirty() -> nil
Forces a refresh during next show()
pixel_size pixel_size() -> int
Returns the number of bytes per pixel
pixel_count pixel_count() -> int
Returns the number of leds in the strip
clear_to clear_to(col:color [, bri:int]) -> nil
Clears all leds to the specified color. bri is optional and default to 255
set_pixel_color set_pixel_color(idx:int, col:color [, bri:int]) -> nil
Set led number idx to the specified color. bri (0..255) is optional and default to 255
get_pixel_color get_pixel_color(idx:int) -> color:int
Returns the color (including brightness and gamma correction) of led number idx
set_gamma set_gamma(gamma:bool) -> nil
Sets whether gamma correction is applied
get_gamma get_gamma() -> bool
Returns whether gamma correction is applied
set_bri set_bri(bri:int) -> nil
Sets the brightness (0..255)
get_bri get_bri() -> int
Returns the current brightness
set_animate set_animate(animate) -> nil
Sets the animation object attached to this strip
get_animate get_animate() -> instance
Returns the animation object attached to this strip
gamma gamma:bool
Applies gamma correction if true (default)
pixels_buffer pixels_buffer() -> bytes()
Returns the internal buffer used by NeoPixelBus. The byte() object points to the original buffer, no new buffer is allocated; which means that raw data can be changed directly. Don't forget to call dirty() and show() afterwards

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.

pixmat class for 2D pixel buffers~

The pixmat class provides a native high-performance 2D pixel buffer abstraction for Berry.
It supports mono (1‑bpp), RGB (3‑bpp), and RGBW (4‑bpp) formats, with optional serpentine layout.

Constructor~

Overload Description
pixmat(bitplane_bytes:bytes, bytes_per_line:int) Creates a 1‑bpp mono matrix from packed bitplane data. Each bit becomes a pixel (0 or 255).
pixmat(buf:bytes, width:int, height:int, bpp:int[, serpentine:bool]) Wraps an existing pixel buffer. No copy is made. bpp is bytes per pixel (1=mono, 3=RGB, 4=RGBA). serpentine reverses odd rows if true.
pixmat(width:int, height:int, bpp:int[, serpentine:bool]) Allocates a new zero‑filled buffer with given dimensions and pixel format.
  • bitplane_bytes: packed bits (1‑bpp), each bit becomes a pixel (0 or 255)
  • buf: external buffer to wrap (no copy)
  • width, height: pixel dimensions
  • bpp: bytes per pixel (1=mono, 3=RGB, 4=RGBW)
  • serpentine: if true, odd rows are reversed in memory

Methods~

Method Description
pixmat.clear([val:int]) Fills the entire matrix with val (default 0). For mono: luminance. For RGB/RGBA: all channels.
pixmat.get(x:int, y:int)int or list Returns pixel value at (x, y). Packed int for mono/RGB/RGBA, list for other bpp.
pixmat.set(x:int, y:int, rgb:int[, bri:int]) Sets pixel at (x, y) using packed RGB (0xRRGGBB). Optional brightness scaling.
pixmat.set(x:int, y:int, h:int, s:int, v:int[, bri:int]) Sets pixel using HSV values. Converts to RGB internally. Optional brightness.
pixmat.blit(src:pixmat, dx:int, dy:int[, bri:int][, tint:int]) Copies pixels from src matrix with optional brightness and RGB tint. Supports mono→color expansion.
pixmat.scroll(dir:int[, src:pixmat]) Scrolls matrix content by one pixel. dir: 0=up, 1=left, 2=down, 3=right. Optional src fills vacated row/column.
  • clear(val): fills matrix with value (default 0)
  • get(x,y): returns pixel value (packed int or list)
  • set(x,y,rgb): sets pixel with packed RGB
  • set(x,y,h,s,v): sets pixel with HSV (converted internally)
  • blit(src, dx, dy): copies pixels from another matrix, for mono source 0 becomes transparent
  • scroll(dir): scrolls content by one pixel (0=up, 1=left, 2=down, 3=right)

Notes~

  • All operations are in-place and use integer math
  • Brightness and tinting are supported in set() and blit()
  • Mono→color expansion is automatic when blitting
  • Ideal for use with Leds.pixels_buffer() to drive 2D LED panels

Example~

var strip = Leds(256, gpio.pin(gpio.WS2812, 32))
var m = pixmat(strip.pixels_buffer(), 32, 8, strip.pixel_size(), true)
m.set(0, 0, 0xFF0000)  # top-left pixel red
strip.show()

A few more examples can be found here.

WLED Palettes Reference~

This page displays all 59 WLED gradient palettes available in the Berry Animation Framework.

Palette Gradient
Analogous
5 color stops
April Night
17 color stops
Aqua Flash
7 color stops
Atlantica
6 color stops
Aurora
6 color stops
Aurora 2
5 color stops
Autumn
13 color stops
Beach
6 color stops
Beech
15 color stops
Blink Red
8 color stops
Breeze
4 color stops
C9
8 color stops
C9 2
10 color stops
C9 New
8 color stops
Candy2
10 color stops
Candy
5 color stops
Cyane
11 color stops
Departure
12 color stops
Drywet
7 color stops
Fairy Reaf
4 color stops
Fire
13 color stops
Grintage
5 color stops
Hult64
8 color stops
Hult
6 color stops
Icefire
7 color stops
Jul
4 color stops
Landscape
9 color stops
Light Pink
11 color stops
Lite Light
6 color stops
Magenta
7 color stops
Magred
5 color stops
Orangery
9 color stops
Orange & Teal
4 color stops
Pastel
11 color stops
Pink Candy
7 color stops
Red & Blue
9 color stops
Red Flash
5 color stops
Red Reaf
4 color stops
Red Shift
7 color stops
Red Tide
11 color stops
Retro Clown
3 color stops
Rewhi
6 color stops
Rivendell
5 color stops
Sakura
5 color stops
Semi Blue
9 color stops
Sherbet
7 color stops
Splash
5 color stops
Sunset2
8 color stops
Sunset
7 color stops
Temperature
18 color stops
Tertiary
5 color stops
Tiamat
11 color stops
Toxy Reaf
2 color stops
Traffic Light
4 color stops
Vintage
8 color stops
Yelblu
5 color stops
Yelblu Hot
7 color stops
Yellowout
2 color stops
Yelmag
7 color stops

Credits~

  • WLED Palettes: From WLED Project by Aircoookie
  • Conversion: For Tasmota Berry Animation Framework
  • Total Palettes: 59 gradient palettes