Lessons and the learning game

Addressable LEDs: strips and matrices

Drive WS2812B strips, rings and panels from an Uno: NeoPixel and FastLED, HSV and palettes, matrix mapping, power budgets and a sound-reactive aurora wall.

Take the course at /learn/path/addressable-leds. It is an intermediate course: it assumes the Uno course.

The lessons

One wire, many lights. A comet on 16 LEDs, with the sketch timing show() in microseconds: 24 bits an LED in GRB order at 800 kHz, each LED keeping its own 24 and passing the rest on. A strip longer than the sketch knows stays dark past the end. Then Adafruit_NeoPixel as a rocket fuel gauge on a knob, with a launch that drains it.

Color like a pro. FastLED on a 16 LED ring: CHSV and CRGB, a hue byte that wraps, a spinning rainbow and saturation on a knob. Then palettes: ocean waves from ColorFromPalette with linear blending, crossfades with nblendPaletteTowardPalette, and a custom aurora palette.

Panels and power. A 16x8 serpentine panel: XY(), the zigzag of odd rows, and a pixel-art spaceship over the stars. Then the power budget: 128 LEDs could draw 7680 mA at full white, so the sketch adds up each frame and limits the brightness to a 500 mA USB port; and power injection for long strips.

Boss. A reactive light wall: an aurora of green and violet curtains made from FastLED noise rises with the sound level from a KY-038, a clap fires a meteor, and a roaring room turns it into a solar storm.

The bench

Every lesson runs on one bench, the gallery's LED layout on a half-size breadboard: a knob on A0, a button on pin 2, and a 330 ohm resistor from pin 6 to the LEDs' DIN, with the LEDs powered from the board's 5 V rails. The LEDs are a 16 LED strip, a 16 LED ring, or a 16x8 serpentine panel (count 128, layout matrix). The boss adds a KY-038 sound sensor, AO on A1 and DO on pin 3.

What each sketch does

  • aledtiming: Adafruit_NeoPixel, 16 LEDs dim blue, show() timed with micros() (596 us), then a comet with a tail that quarters each step.
  • aledneo: a fuel gauge from the knob, red to green, setBrightness(60), and a launch on the button.
  • aledhsv: FastLED, a CHSV to CRGB table, a rainbow with DELTA_HUE 16 spinning on the ring, saturation from the knob.
  • aledpalette: Ocean, Lava, Forest and a custom Aurora palette on the button, crossfaded with MAX_CHANGES 24 and the frames counted.
  • aledmatrix: XY() with a SERPENTINE flag, the map printed, a spaceship sprite from strings of color letters.
  • aledpower: white, rainbow and night sky scenes, each frame's current summed at 20 mA a channel and the brightness limited to BUDGET_MA.
  • aledboss: the aurora wall: peak-to-peak swing from 60 samples, the first DO edge for a meteor, and STORM_COUNTS for the solar storm.

Honest limits

  • The LEDs draw no current in the simulator. The power lesson does the sum a real build needs, and FastLED's setMaxPowerInVoltsAndMilliamps() is accepted but limits nothing, so the sketch limits the brightness itself.
  • Voltage drop along a strip is not modeled: the far end never turns yellow. Power injection is taught, not shown.
  • FastLED's CHSV conversion, noise and named palettes are close to upstream, not identical, so colors can differ by a few counts from a real board.
  • The KY-038 hears the room level you set on its slider and its clap button, not your computer's microphone. Below about 75 dB its output does not move at all; a real one wobbles by a count or two of its own hiss.

Displays: characters, digits and dots covers LCDs, seven-segment digits and the MAX7219 matrix, and the gallery has many WS2812 projects, from a rainbow arch to a 16x16 rangoli panel.