You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This AtomVM Erlang library and Nif can be used to control WS2812 and SK6812 LED strips using the ESP32 SoC for any Erlang/Elixir programs targeted for AtomVM on the ESP32 platform.
Features
RGB LED support (WS2812, WS2812B) - 24-bit color (3 bytes per pixel)
RGBW LED support (SK6812) - 32-bit color with dedicated white channel (4 bytes per pixel)
Global brightness control - Efficient brightness scaling (0-255) applied at refresh time
Multiple color spaces - RGB, RGBW, HSV, and HSVW
Batch operations - Fill entire strip or set multiple pixels in a single call
Multiple strips - Drive multiple LED strips simultaneously on different GPIO pins
ESP-IDF 5.x compatible - Uses the new RMT driver API
This Nif is included as an add-on to the AtomVM base image. In order to use this Nif in your AtomVM program, you must be able to build the AtomVM virtual machine, which in turn requires installation of the Espressif IDF SDK and tool chain.
Quick Start
Basic Usage (Erlang)
%% Start a 4-pixel RGB LED strip on GPIO pin 18
{ok, LedStrip} =led_strip:start(18, 4),
%% Set individual pixels using RGB (0-255 per channel)ok=led_strip:set_pixel_rgb(LedStrip, 0, 255, 0, 0), %% Redok=led_strip:set_pixel_rgb(LedStrip, 1, 0, 255, 0), %% Greenok=led_strip:set_pixel_rgb(LedStrip, 2, 0, 0, 255), %% Blueok=led_strip:set_pixel_rgb(LedStrip, 3, 255, 255, 0), %% Yellow%% Refresh to display changesok=led_strip:refresh(LedStrip).
Basic Usage (Elixir)
# Start a 4-pixel RGB LED strip on GPIO pin 18{:ok,led_strip}=:led_strip.start(18,4)# Set individual pixels using RGB (0-255 per channel):ok=:led_strip.set_pixel_rgb(led_strip,0,255,0,0)# Red:ok=:led_strip.set_pixel_rgb(led_strip,1,0,255,0)# Green:ok=:led_strip.set_pixel_rgb(led_strip,2,0,0,255)# Blue:ok=:led_strip.set_pixel_rgb(led_strip,3,255,255,0)# Yellow# Refresh to display changes:ok=:led_strip.refresh(led_strip)
RGBW Strip (SK6812)
%% Start a 4-pixel RGBW strip
{ok, LedStrip} =led_strip:start(18, 4, #{led_type=>rgbw}),
%% Set pixels with RGBW (includes dedicated white channel)ok=led_strip:set_pixel_rgbw(LedStrip, 0, 255, 0, 0, 0), %% Pure redok=led_strip:set_pixel_rgbw(LedStrip, 1, 0, 0, 0, 255), %% Pure white LEDok=led_strip:refresh(LedStrip).
HSV Color Space
%% HSV: Hue (0-359), Saturation (0-100), Value (0-100)ok=led_strip:set_pixel_hsv(LedStrip, 0, 0, 100, 50), %% Red at 50% brightnessok=led_strip:set_pixel_hsv(LedStrip, 1, 120, 100, 50), %% Greenok=led_strip:set_pixel_hsv(LedStrip, 2, 240, 100, 50), %% Blueok=led_strip:refresh(LedStrip).
Fill Entire Strip
%% Fill all pixels with the same colorok=led_strip:fill_rgb(LedStrip, 255, 0, 255), %% Magentaok=led_strip:refresh(LedStrip).
%% Or with HSVok=led_strip:fill_hsv(LedStrip, 180, 100, 50), %% Cyanok=led_strip:refresh(LedStrip).
Set Multiple Pixels at Once
%% Set multiple pixels with a list of RGB tuplesColors= [{255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 0}],
ok=led_strip:set_pixels_rgb(LedStrip, Colors),
ok=led_strip:refresh(LedStrip).
%% With explicit starting indexok=led_strip:set_pixels_rgb(LedStrip, Colors, 0),
ok=led_strip:refresh(LedStrip).
Brightness Control
%% Set global brightness (0-255, default is 255)ok=led_strip:set_brightness(LedStrip, 128), %% 50% brightness%% Get current brightnessBrightness=led_strip:get_brightness(LedStrip).