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

Libraries / LEDs

Arduino library · LEDs

# WS2812FX: ready-made animations for a WS2812 strip

WS2812FX by Harm Aldick gives a WS2812 strip over fifty named animations, picked by number: FX_MODE_RAINBOW_CYCLE, FX_MODE_LARSON_SCANNER, FX_MODE_THEATER_CHASE, FX_MODE_FIRE_FLICKER and many more. You choose a mode, a color, a speed and a brightness, call start(), and the library animates the strip while your loop() does other work.

Open the example in the editor See the calls

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

## What WS2812FX does

The key is service(). It must be called on every pass of loop(); each call checks the time and draws the next frame only if one is due, so nothing blocks. A delay() of a second in loop() freezes the effect for that second. Speed is roughly the time one cycle of an effect takes in milliseconds, so a larger number is slower.

Segments split one strip into parts that each run their own effect, with setSegment(). WS2812FX is built on Adafruit_NeoPixel, so it runs on the same boards and takes the same strip type flags. In Mokxi the mode numbers and names are the library’s, but the animations are Mokxi’s own versions of what each name describes, and a few rarer modes borrow a similar effect.

Library Manager name | WS2812FX

Author | Harm Aldick

Include | #include <WS2812FX.h>

Boards | Arduino Uno, Arduino Nano, Arduino Mega 2560, Arduino Leonardo, SparkFun Pro Micro, Arduino Micro, Arduino Pro Mini 3.3 V, 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, 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 <WS2812FX.h> and the sketch compiles, with no download, no zip and no Library Manager.

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

What to know in the simulator: The mode numbers and names are upstream’s; the animations are Mokxi’s own renditions, and some modes borrow a similar one.

- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- Arduino Pro Mini 3.3 V
- 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.

### WS2812FX ws2812fx = WS2812FX(8, 6, NEO_GRB + NEO_KHZ800)

Eight LEDs on pin 6, with the strip type flags Adafruit_NeoPixel uses.

### ws2812fx.init()

Sets the strip up. Call it before any other setting, once in setup().

### ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE)

Chooses the effect by its number. getModeCount() says how many there are, for a button that steps through them.

### ws2812fx.setSpeed(1000)

Sets how long one cycle of the effect takes, roughly in ms. 200 is brisk, 3000 is slow and calm.

### ws2812fx.setColor(0x00FF00)

The main color for effects that use one, such as color wipe, scan and breath. It also takes red, green and blue as three numbers.

### ws2812fx.start()

Starts the animation. stop() halts it and turns the strip off; isRunning() says which.

### ws2812fx.service()

Draws the next frame when one is due. The only call loop() needs.

### ws2812fx.getModeName(ws2812fx.getMode())

The current effect’s name as text, such as "Rainbow Cycle", handy for a Serial menu or a display.

### ws2812fx.setSegment(0, 0, 3, FX_MODE_SCAN, RED, 1000, false)

Makes LEDs 0 to 3 a segment with its own mode, color and speed. The last argument reverses its direction.

## Example: A rainbow cycle with WS2812FX

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

### The strip lights for one frame and then freezes

service() is not in loop(), or loop() spends most of its time in delay(). Call service() on every pass and replace delays with millis() timers.

### setMode() seems to do nothing

Settings take effect once the strip is running. Call init() first, then the settings, then start(); and check that the mode number is below getModeCount().

### Colors are wrong, red shows as green

The strip type flag does not match the LEDs. Most WS2812B strips need NEO_GRB + NEO_KHZ800 in the constructor; NEO_RGB is for the few that take red first.

## Keep going

### Learn

- Arduino NeoPixel (WS2812B): Wiring and Code
- Arduino millis(): Timers and Multiple Tasks

### Parts

- Addressable RGB LEDs

### More leds libraries

- Arduino_LED_Matrix (Uno R4 core)
- Adafruit NeoPixel
- FastLED
- Adafruit NeoMatrix
- NeoPixelBus by Makuna
- Adafruit DotStar

Every built-in library · Open the editor

## Try WS2812FX without installing anything

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

Start building free

Open the editor
