src/README.md
src/)This document introduces the FastLED source tree housed under src/, first by mapping the major directories and public headers, then providing a practical guide for two audiences:
The src/ directory contains the classic FastLED public API (FastLED.h), the cross‑platform fl:: foundation, effect/graphics utilities, platform backends, sensors, fonts/assets, and selected third‑party shims.
src/FastLED.h and classic public headers for sketchesfl/: cross‑platform foundation (containers, math, graphics primitives, async, JSON)fx/: effect/graphics utilities and 1D/2D composition helpersplatforms/: hardware abstraction layers (AVR, ARM, ESP, POSIX, STUB, WASM, etc.)fl/sensors/: basic input components (buttons, digital pins)fl/font/: TrueType and bitmap font support for text renderingthird_party/: vendored minimal headers and compatibility glueIf you are writing Arduino‑style sketches, include FastLED.h. For advanced/host builds or portable C++, prefer including only what you use from fl/ and related subsystems.
#include <FastLED.h> for the canonical API"fl/stl/vector.h", "fl/downscale.h", "fx/frame.h")fl:: facilities to keep portability across compilers and embedded targets. See src/fl/README.md for the full fl:: guide.FastLED.h, color types, core utilities, and historical compatibility headersfl:: drawing/mapping)fl/src/fl/README.md for a comprehensive breakdownfx/platforms/fl/sensors/button, digital_pin) intended for demos and portable logicfl/font/truetype.h)console_font_4x6, console_font_5x8) for text overlays in demos/testssrc/fl/font/README.md for detailed documentation and BETA status warningsthird_party/arduinojson headers and platform shims kept intentionally minimalThe following examples show how to use common capabilities reachable from src/.
#include <FastLED.h>
constexpr uint16_t NUM_LEDS = 144;
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, 5, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(160);
}
void loop() {
fill_rainbow(leds, NUM_LEDS);
FastLED.show();
}
fl::Leds + XYMap#include <FastLED.h>
#include "fl/leds.h"
#include "fl/xymap.h"
constexpr uint16_t WIDTH = 16;
constexpr uint16_t HEIGHT = 16;
constexpr uint16_t NUM_LEDS = WIDTH * HEIGHT;
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, 5, GRB>(leds, NUM_LEDS);
}
void loop() {
auto map = fl::XYMap::constructSerpentine(WIDTH, HEIGHT);
fl::Leds s = fl::Leds(leds, map);
for (uint16_t y = 0; y < HEIGHT; ++y) {
for (uint16_t x = 0; x < WIDTH; ++x) {
uint8_t hue = uint8_t((x * 255u) / (WIDTH ? WIDTH : 1));
s(x, y) = CHSV(hue, 255, 255);
}
}
FastLED.show();
}
#include "fl/downscale.h"
#include "fl/upscale.h"
#include "fl/grid.h"
// High‑def buffer drawn elsewhere
fl::Grid<CRGB> srcHD(64, 64);
// Downscale into your physical panel resolution
fl::Grid<CRGB> panel(16, 16);
void render_frame() {
fl::downscale(srcHD, srcHD.size_xy(), panel, panel.size_xy());
}
#include <FastLED.h>
#include "fl/ui.h"
UISlider brightness("Brightness", 128, 0, 255);
UICheckbox enabled("Enabled", true);
void setup() {
brightness.onChanged([](UISlider& s){ FastLED.setBrightness((uint8_t)s); });
}
void loop() {
FastLED.show();
}
See src/fl/README.md and platforms/shared/ui/json/readme.md for JSON UI lifecycle and platform bridges.
FastLED.hCRGB* as an fl::Leds surface for 2D rendering)fl:: namespace offers:
vector, span, slice)raster, xymap, rectangular_draw_buffer)downscale, upscale, supersample)hsv, hsv16, gamma, gradient, sin32, random)task, promise, function_list)json, ostream, printf)src/fl/README.mdfx/ contains an effect pipeline with frames, layers, and video helpersfl::Ledsfx/frame.h, fx/detail/*, fx/video/* (exact APIs evolve; see headers)platforms/stub/: host/test builds without hardware; ideal for CI and examplesplatforms/wasm/: web builds with JSON UI, Asyncify integration, and JS glueplatforms/arm/, platforms/esp/, platforms/avr/, platforms/posix/: target‑specific shimsplatforms/*/*.h and platforms/ui_defs.hFASTLED_USE_JSON_UI=1)src/platforms/wasm/ui.cpp, JS modules)fl::task/engine events integration; see examples in examples/ under wasm/ topicstests/ and CI utilities under ci/fl:: primitives and compile‑time guards (compiler_control.h, warn.h, assert.h)FastLED.h and follow examples in examples/CRGB* with fl::Leds and an fl::XYMapsupersample + downscale to preserve detailfl:: as an embedded‑friendly STL and graphics/math foundation; prefer fl::span<T> for parametersfl/ headers rather than raw pragmasplatforms/ shims and use the STUB backend for host testsfl::memfill over memset where applicable to match codebase idiomsThis README will evolve alongside the codebase. For subsystem details, jump into the directories listed above and consult header comments and src/fl/README.md for the foundation layer.