LED Segments - An Arduino lib to abstract individual LEDs on a strip into virtual Pixels and Segments
This library provides a way to map an LED strip into one or more physical layouts. This is useful for managing effects on LED displays where different sections need to be controlled independently but where the LEDs are addressed by their linear indexes (e.g. a display sign where each letter is a section of the same strip).
It provides a simple way to segment a display where the physical location of LEDs has little correlation to their addressable index, e.g. displays with complex shapes.
Multiple layouts can be defined, if required, to allow for the display to be segmented in different ways while making it easy to switch from one layout to another during rendering.
Step 1: Install the Library
- Go to LED-Segments GitHub
- Click Code → Download ZIP
- In Arduino IDE: Sketch → Include Library → Add .ZIP Library
- Select the downloaded ZIP file
- Install FastLED library: Tools → Manage Libraries → Search "FastLED" → Install
Step 2: Run the Example
- File → Examples → LED-Segments → BasicUsage
- Connect your LED strip to the pin defined in
MatrixDisplaySpec.h(default: pin 9) - Select your board: Tools → Board
- Select your port: Tools → Port
- Click Upload ⬆️
Method A: Use as Library Dependency (Recommended)
- Create a new PlatformIO project
- Add to your
platformio.ini:
lib_deps =
https://github.com/pthomain/LED-Segments.git
fastled/FastLED@^3.10.0
build_flags = -std=c++17- Copy the example code from
examples/BasicUsage/to yoursrc/main.cpp - Run:
pio lib install(installs dependencies) - Run:
pio run -t upload
Note: Use platformio.ini configuration instead of pio lib install LED-Segments since this library is hosted on GitHub, not the PlatformIO Registry.
Method B: Clone and Deploy Directly
# Clone and enter directory
git clone https://github.com/pthomain/LED-Segments.git
cd LED-Segments
# Deploy to your board (modify platformio.ini to use BasicUsage as src)
# Note: This method requires manual configuration- LED Strip Data Pin → Arduino Pin 9 (or modify in
MatrixDisplaySpec.h) - LED Strip Power → External 5V power supply (for >30 LEDs)
- LED Strip Ground → Arduino Ground + Power supply Ground
- Seeed Xiao (default configuration)
- Arduino Uno
- ESP32
- Most Arduino-compatible boards with C++17 support
- FastLED 3.10.0 or later
- C++17 compatible compiler
Individual LEDs aren't addressed directly but are instead abstracted into Pixels and Segments:
- Each Layout is composed of at least one Segment and each Segment is composed of at least one Pixel.
- Each Pixel is itself composed of one or more LEDs.
- LED indexes do not have to be contiguous in a given Pixel, providing flexibility to displays where you might want to group LEDs that are physically close together but far from each other in terms of their indexes on the strip.
Custom effects can be applied to any given Layout, where they are repeatedly applied to each Segment, using Pixel as the smallest addressable unit for applying a colour. By randomising layouts in the rendering loop, you can achieve a multitude of different ways to render the same effect.
The examples/BasicUsage/ directory contains a fully functional example. Here's the basic structure:
#include <LED-Segments.h>
#include "spec/MatrixDisplaySpec.h"
using namespace LEDSegments;
using SPEC = MatrixDisplaySpec;
std::unique_ptr<Display<SPEC>> display;
void setup() {
Serial.begin(9600);
delay(2000);
display = std::make_unique<Display<SPEC>>();
}
void loop() {
display->loop();
}Key Components:
MatrixDisplaySpec: Defines your LED layout, segments, and configurationDisplay<SPEC>: Main controller that handles effects, overlays, and transitions- Automatic Effects: The display automatically cycles through different visual effects
- Copy
examples/BasicUsage/spec/MatrixDisplaySpec.hto your project - Modify the layout configuration for your specific LED setup:
- Change
LED_PINfor your data pin - Adjust
nbLeds()for your strip length - Customize
segmentSize()for your layout segments
- Change
"LED-Segments.h: No such file or directory"
- Make sure you installed the library correctly
- For PlatformIO: Check that
lib_depsincludes the GitHub URL
"error: 'std::make_unique' was not declared"
- Add
build_flags = -std=c++17to your platformio.ini - For Arduino IDE: Use Tools → Board → Board Manager and ensure C++17 support
LEDs not lighting up
- Check wiring connections
- Verify LED strip type matches
LED_TYPEin your DisplaySpec - Ensure adequate power supply for your LED count
Compilation errors with FastLED
- Make sure FastLED version is 3.10.0 or later
- Check that your board supports the LED strip type you're using
- Check the complete working example in
examples/BasicUsage/ - Review the
wiki/directory for detailed documentation - Open an issue on GitHub for specific problems
For advanced customization, see:
wiki/DisplaySpec.md- Creating custom display layoutswiki/Effects.md- Available effects and parameterswiki/Overlays.md- Overlay effects for additional visual layerswiki/Transitions.md- Smooth transitions between effects