Arduino library · LEDs

LiteLED: an example that runs

Yes. You can use the LiteLED library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (Addressable RGB LEDs). The example below, "Three colors on a strip with LiteLED on an ESP32-C3", runs on the ESP32-C3-DevKitM-1.

Built in on Mokxi: #include <LiteLED.h> and it builds, with nothing to install. Free, and no account needed.

What LiteLED does

WS2812, SK6812, APA106 and SM16703 strips on an ESP32: setPixel(), fill(), brightness() and show(). That is what LiteLED, by Xylopyrographer, covers. The sketch below uses it on the ESP32-C3-DevKitM-1: “Three colors on a strip with LiteLED on an ESP32-C3”.

The interface of Xylopyrographer's "LiteLED" library (3.2.x): WS2812 and other one-wire RGB LED strips on an ESP32, with a brightness applied as the strip is sent.

Use the ws2812 part, its DIN on the data pin. Every type is sent at WS2812 timing; the types differ in their color order (GRB for WS2812 and SK6812, RGB for WS2812_RGB, APA106 and SM16703) and RGBW strips send a fourth, white byte (the color's luma when auto_w is on).

The calls follow release 3.2.0 of the library, so a sketch written here builds on a real board too. The example is the one Mokxi's own tests build and run, so what is printed here is what runs.

Library Manager nameLiteLED
AuthorXylopyrographer
Include#include <LiteLED.h>
BoardsESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesAddressable RGB LEDs

Install it

It builds on ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32.

In Mokxi it is built in: #include <LiteLED.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "LiteLED" by Xylopyrographer from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add LiteLED to lib_deps in PlatformIO. Mokxi follows the calls of release 3.2.0, so a sketch written here builds there too.

What to know in the simulator: The bits are timed on the core rather than sent by the RMT, every type at WS2812 timing. The DMA, priority and PSRAM options change nothing, and the LiteLEDpio (PARLIO) classes are not here.

The calls you will use

In the order a sketch meets them.

LiteLED myLED(LED_TYPE, LED_TYPE_IS_RGBW)

Makes myLED, the LiteLED object the calls below are made on.

myLED.begin(LED_GPIO, LED_COUNT)

Starts it up. Call it once in setup(). Arguments: data pin, length, auto w.

myLED.setPixel(0, L_RED)

Sets the pixel to the value you pass in.

myLED.getPixelC(1)

Returns PixelC as a crgb_t.

myLED.getBrightness()

Returns the brightness as a whole number.

Example: Three colors on a strip with LiteLED on an ESP32-C3

On the ESP32-C3-DevKitM-1. It runs in the browser exactly as printed.

sketch.ino · ESP32-C3-DevKitM-1
#include <LiteLED.h>

#define LED_TYPE LED_STRIP_WS2812
#define LED_TYPE_IS_RGBW 0
#define LED_GPIO 6
#define LED_COUNT 8
#define LED_BRIGHT 30

static const crgb_t L_RED = 0xff0000;
static const crgb_t L_GREEN = 0x00ff00;
static const crgb_t L_BLUE = 0x0000ff;

LiteLED myLED(LED_TYPE, LED_TYPE_IS_RGBW);

void setup() {
  Serial.begin(115200);
  if (myLED.begin(LED_GPIO, LED_COUNT) != ESP_OK) {
    Serial.println("begin failed");
    return;
  }
  myLED.brightness(LED_BRIGHT);
  myLED.setPixel(0, L_RED);
  myLED.setPixel(1, L_GREEN);
  myLED.setPixel(2, L_BLUE, 1);   // and show
  Serial.print("pixel 1 is 0x");
  Serial.println(myLED.getPixelC(1), HEX);
  Serial.print("brightness ");
  Serial.println(myLED.getBrightness());
}

void loop() {}

Wiring

  • ESP32-C3-DevKitM-1 6 to Addressable RGB LEDs DIN
  • ESP32-C3-DevKitM-1 5V to Addressable RGB LEDs VDD
  • ESP32-C3-DevKitM-1 GND to Addressable RGB LEDs VSS

Open it in the editor, wired and ready to run

Try LiteLED without installing anything

Open the example, change the sketch, and keep your version in a free account.