Source: https://mokxi.com/libraries/fastled
Updated: 2026-11-02

Libraries / LEDs
Arduino library · LEDs

# FastLED: color math and effects for LED strips

FastLED drives the same addressable strips as Adafruit NeoPixel, the WS2812B, WS2811 and SK6812, and dozens of other chipsets, but its real draw is the toolkit around them: fast 8-bit color math, HSV colors, palettes, noise, and helpers for timing animations without delay(). Most of the strip effects you find online are written with it.

Open the example in the editor See the calls

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

## What FastLED does

The colors live in an array your sketch owns, CRGB leds[NUM_LEDS]. You change entries the way you change any array, leds[0] = CRGB::Red, and FastLED.show() sends the whole array to the strip. addLeds() binds the array to a chipset, a data pin and a color order, all given as template arguments in angle brackets.

Because those are template arguments, the data pin must be a constant known when the sketch compiles: a number or a #define, not a variable read at run time. That rule is behind the most confusing FastLED compile errors.

Library Manager name | FastLED

Author | Daniel Garcia, Mark Kriegsman

Include | #include <FastLED.h>
#include <lib8tion.h>
#include <pixeltypes.h>
#include <colorutils.h>

Boards | Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ATtiny85, 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, Raspberry Pi Pico, Raspberry Pi Pico W, Arduino Nano RP2040 Connect, Seeed XIAO RP2040, Waveshare RP2040-Zero, Arduino Uno R4, Arduino Uno R4 WiFi

In the simulator | Runs, with a gap the note below names.

Parts it drives | Addressable RGB LEDs

## Install it

It builds on Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, ATtiny85, 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, Raspberry Pi Pico, Raspberry Pi Pico W, Arduino Nano RP2040 Connect, Seeed XIAO RP2040, Waveshare RP2040-Zero, Arduino Uno R4, Arduino Uno R4 WiFi.

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

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

What to know in the simulator: The one-wire chipsets run where Adafruit_NeoPixel does. CHSV colors, sin8 and inoise8 are close approximations, the named palettes other than RainbowColors_p are Mokxi’s gradients, and power limiting does nothing. The Fx engine (fx/, fl/ui.h) and the platform drivers (OctoWS2811, SmartMatrix, parallel ports) are not here.

Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · Arduino Pro Mini 3.3 V · ATtiny85 · 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 · Raspberry Pi Pico · Raspberry Pi Pico W · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### CRGB leds[NUM_LEDS]

The color of every LED, three bytes each. Your sketch writes to it directly.

### FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS)

Connects the array to a WS2812B strip on DATA_PIN with green-red-blue order. Call it once in setup().

### FastLED.setBrightness(64)

Overall brightness from 0 to 255, applied as the data is sent, so the array keeps its full colors.

### FastLED.show()

Sends the array to the strip. Call it once per frame after changing the colors.

### leds[i] = CHSV(hue, 255, 255)

Sets a color by hue, saturation and value, each 0 to 255. Stepping the hue is the easy way to rainbow effects.

### fill_rainbow(leds, NUM_LEDS, startHue, 7)

Fills the array with a rainbow starting at startHue, moving 7 hue steps per LED.

### fadeToBlackBy(leds, NUM_LEDS, 20)

Dims every LED a little each frame, which leaves fading trails behind a moving dot.

### beatsin8(30, 0, 255)

A value that swings between 0 and 255 like a sine wave, 30 times a minute, computed from the clock with no state to keep.

### EVERY_N_MILLISECONDS(20) { hue++; }

Runs the block at most once every 20 ms, a way to pace one part of an animation without delay().

## Example: A FastLED rainbow

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

### Wiring

- Arduino Uno R3 6 to Addressable RGB LEDs DIN
- Arduino Uno R3 5V to Addressable RGB LEDs VDD
- Arduino Uno R3 GND to Addressable RGB LEDs VSS

Open it in the editor, wired and ready to run

## Common errors and how to fix them

### no matching function for call to 'CFastLED::addLeds<WS2812B, dataPin, GRB>(...)'

The pin is a variable. FastLED needs it at compile time: write the number, or use #define DATA_PIN 6 or const uint8_t DATA_PIN = 6 at file scope.

### Colors are wrong: blue shows as red

The color order is not the strip’s. WS2812B strips are GRB; try RGB or BRG in the addLeds template until CRGB::Red shows red.

### The strip lights but never changes

FastLED.show() is missing after the array is updated, or a delay() inside the effect stops loop() for a long time. Call show() once per frame and pace with EVERY_N_MILLISECONDS.

## Questions and answers

### Is FastLED’s color math exact on Mokxi?

Most of it follows FastLED’s documented formulas. CHSV to RGB, sin8() and cos8(), and the noise functions are Mokxi’s own approximations and can differ by a few counts, and the named palettes are generated rather than copied, so colors can look slightly different from a real strip.

## Keep going

### Learn

- Arduino NeoPixel (WS2812B): Wiring and Code
- ESP32 NeoPixel (WS2812B) Rainbow Tutorial

### Parts

- Addressable RGB LEDs

### More leds libraries

- Arduino_LED_Matrix (Uno R4 core)
- Adafruit NeoPixel

Every built-in library · Open the editor

## Try FastLED without installing anything

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

Start building free

Open the editor
