FastLED 3.10.6
Loading...
Searching...
No Matches
AnimartrixRing.ino

This is the minimal demo of the technique: render Animartrix into a rectangular grid, then sample a circle out of that grid with a ScreenMap and Fx2dTo1d.

This is the minimal demo of the technique: render Animartrix into a rectangular grid, then sample a circle out of that grid with a ScreenMap and Fx2dTo1d. Nothing else. No audio, no state machine, no orchestration.

Animartrix (16x16 grid) -> ScreenMap (circle of NUM_LEDS points) -> Fx2dTo1d (bilinear sample) -> 1D ring

Pick an animation from the dropdown, scrub the speed slider, watch how each Animartrix pattern reads once it has been wrapped around a ring. That is the whole point of this sketch.

Looking for the audio-reactive version? That moved to examples/MoodRing/, which is the product-track sketch (sound classification, per-state visual banks, mood mapping). See issue #2256.

This sketch is fully compatible with the FastLED web compiler:

  1. pip install fastled
  2. cd into this directory
  3. run fastled
// @filter: (memory is large)
// Use SPI-based WS2812 driver instead of RMT on ESP32
#define FASTLED_ESP32_USE_CLOCKLESS_SPI
// FastLED.h must be included first to trigger precompiled headers for FastLED's
// build system
#include "FastLED.h"
#include "fl/ui/ui.h"
#include "auto_brightness.h"
#include "ring_screenmap.h"
FASTLED_TITLE("AnimartrixRing");
#define NUM_LEDS 244
#ifndef PIN_DATA
#define PIN_DATA 3 // ESP32C6 has this random pin available on the break out.
#endif // PIN_DATA
#define BRIGHTNESS 8
// Grid dimensions for Animartrix sampling
#define GRID_WIDTH 16
#define GRID_HEIGHT 16
// 0.15 cm or 1.5mm -- appropriate for a dense LED rope.
#define LED_DIAMETER 0.15f
#define FIRST_ANIMATION fl::AnimartrixAnim::SLOW_FADE
// Animartrix 2D effect: the source image the ring samples from.
XYMap xymap = XYMap::constructRectangularGrid(GRID_WIDTH, GRID_HEIGHT);
// ScreenMap for the ring: places each LED on a circle inside the grid.
// The 2D-to-1D sampling effect: bilinear-samples the grid at each ring point.
// FxEngine for the 1D strip
// UI controls. The dropdown order matches fl::AnimartrixAnim exactly, so the
// selected index can be handed straight to Animartrix::fxSet().
// Title comes from FASTLED_TITLE above -- do not declare a second fl::UITitle.
"Samples a circular ring out of a 2D Animartrix grid. @author of fx is "
"StefanPetrick");
fl::UIDropdown fxIndex("Animartrix - index", {
"RGB_BLOBS5", "RGB_BLOBS4", "RGB_BLOBS3", "RGB_BLOBS2", "RGB_BLOBS",
"POLAR_WAVES", "SLOW_FADE", "ZOOM2", "ZOOM", "HOT_BLOB",
"SPIRALUS2", "SPIRALUS", "YVES", "SCALEDEMO1", "LAVA1",
"CALEIDO3", "CALEIDO2", "CALEIDO1", "DISTANCE_EXPERIMENT", "CENTER_FIELD",
"WAVES", "CHASING_SPIRALS", "ROTATING_BLOB", "RINGS", "COMPLEX_KALEIDO",
"COMPLEX_KALEIDO_2", "COMPLEX_KALEIDO_3", "COMPLEX_KALEIDO_4", "COMPLEX_KALEIDO_5", "COMPLEX_KALEIDO_6",
"WATER", "PARAMETRIC_WATER", "MODULE_EXPERIMENT1", "MODULE_EXPERIMENT2", "MODULE_EXPERIMENT3",
"MODULE_EXPERIMENT4", "MODULE_EXPERIMENT5", "MODULE_EXPERIMENT6", "MODULE_EXPERIMENT7", "MODULE_EXPERIMENT8",
"MODULE_EXPERIMENT9", "MODULE_EXPERIMENT10", "MODULE_EXPERIMENT_SM1", "MODULE_EXPERIMENT_SM2", "MODULE_EXPERIMENT_SM3",
"MODULE_EXPERIMENT_SM4", "MODULE_EXPERIMENT_SM5", "MODULE_EXPERIMENT_SM6", "MODULE_EXPERIMENT_SM8", "MODULE_EXPERIMENT_SM9",
"MODULE_EXPERIMENT_SM10", "FLUFFY_BLOBS"
});
fl::UISlider timeSpeed("Time Speed", 1, -10, 10, .1);
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255, 1);
fl::UICheckbox autoBrightness("Auto Brightness", true);
fl::UISlider autoBrightnessMax("Auto Brightness Max", 84, 0, 255, 1);
fl::UISlider autoBrightnessLowThreshold("Auto Brightness Low Threshold", 8, 0,
100, 1);
fl::UISlider autoBrightnessHighThreshold("Auto Brightness High Threshold", 22,
0, 100, 1);
void setup() {
Serial.begin(115200);
// Setup LED strip
FastLED.addLeds<WS2812, PIN_DATA>(leds, NUM_LEDS)
.setCorrection(TypicalLEDStrip)
.setScreenMap(screenmap);
FastLED.setBrightness(brightness.value());
// Add the 2D-to-1D effect to FxEngine
// Dropdown index maps 1:1 onto fl::AnimartrixAnim, so point it at the boot
// animation -- otherwise the UI would read "RGB_BLOBS5" (index 0) while
// FIRST_ANIMATION was actually rendering. loop() reconciles from there.
fxIndex.setSelectedIndex(static_cast<int>(FIRST_ANIMATION));
Serial.println("AnimartrixRing setup complete");
}
void loop() {
// Poll rather than use onChanged(): a value the web UI restores (persisted
// or from the URL) can land before the first frame, where the change
// detector absorbs it into its baseline and never fires. Comparing against
// the animation we last pushed cannot miss it. Same pattern as
// examples/Animartrix/Animartrix.ino.
static int sLastFxIndex = -1;
if (fxIndex.as_int() != sLastFxIndex) {
sLastFxIndex = fxIndex.as_int();
animartrix->fxSet(sLastFxIndex);
}
fxEngine.setSpeed(timeSpeed.value());
// Draw the effect
fxEngine.draw(millis(), leds);
// Calculate final brightness
uint8_t finalBrightness;
if (autoBrightness.value()) {
float avgBri = getAverageBrightness(leds);
finalBrightness = applyBrightnessCompression(
avgBri, static_cast<uint8_t>(autoBrightnessMax.value()),
} else {
finalBrightness = static_cast<uint8_t>(brightness.value());
}
FastLED.setBrightness(finalBrightness);
FastLED.show();
}
CRGB leds[1]
void setup()
void loop()
fl::FxEngine fxEngine(NUM_LEDS)
#define NUM_LEDS
fl::UIDescription description("Demo of the Animatrix effects. @author of fx is StefanPetrick")
fl::Animartrix animartrix(xyMap, FIRST_ANIMATION)
#define PIN_DATA
#define LED_DIAMETER
fl::UIDropdown fxIndex("Animartrix - index", { "RGB_BLOBS5", "RGB_BLOBS4", "RGB_BLOBS3", "RGB_BLOBS2", "RGB_BLOBS", "POLAR_WAVES", "SLOW_FADE", "ZOOM2", "ZOOM", "HOT_BLOB", "SPIRALUS2", "SPIRALUS", "YVES", "SCALEDEMO1", "LAVA1", "CALEIDO3", "CALEIDO2", "CALEIDO1", "DISTANCE_EXPERIMENT", "CENTER_FIELD", "WAVES", "CHASING_SPIRALS", "ROTATING_BLOB", "RINGS", "COMPLEX_KALEIDO", "COMPLEX_KALEIDO_2", "COMPLEX_KALEIDO_3", "COMPLEX_KALEIDO_4", "COMPLEX_KALEIDO_5", "COMPLEX_KALEIDO_6", "WATER", "PARAMETRIC_WATER", "MODULE_EXPERIMENT1", "MODULE_EXPERIMENT2", "MODULE_EXPERIMENT3", "MODULE_EXPERIMENT4", "MODULE_EXPERIMENT5", "MODULE_EXPERIMENT6", "MODULE_EXPERIMENT7", "MODULE_EXPERIMENT8", "MODULE_EXPERIMENT9", "MODULE_EXPERIMENT10", "MODULE_EXPERIMENT_SM1", "MODULE_EXPERIMENT_SM2", "MODULE_EXPERIMENT_SM3", "MODULE_EXPERIMENT_SM4", "MODULE_EXPERIMENT_SM5", "MODULE_EXPERIMENT_SM6", "MODULE_EXPERIMENT_SM8", "MODULE_EXPERIMENT_SM9", "MODULE_EXPERIMENT_SM10", "FLUFFY_BLOBS" })
fl::UISlider timeSpeed("Time Speed", 1, -10, 10,.1)
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
#define BRIGHTNESS
#define FIRST_ANIMATION
uint8_t applyBrightnessCompression(float inputBrightnessPercent, uint8_t maxBrightness, float lowThreshold, float highThreshold)
float getAverageBrightness(fl::span< const CRGB > leds)
fl::ScreenMap makeRingScreenMap(int numLeds, int gridWidth, int gridHeight, float diameter)
XYMap xymap
#define GRID_WIDTH
fl::ScreenMap screenmap
#define GRID_HEIGHT
fl::UISlider autoBrightnessLowThreshold("Auto Brightness Low Threshold", 8, 0, 100, 1)
fl::UICheckbox autoBrightness("Auto Brightness", true)
fl::UISlider autoBrightnessHighThreshold("Auto Brightness High Threshold", 22, 0, 100, 1)
fl::UISlider autoBrightnessMax("Auto Brightness Max", 84, 0, 255, 1)
FASTLED_TITLE("AnimartrixRing")
auto fx2dTo1d
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
@ BILINEAR
Bilinear interpolation (smooth)
Definition fx2d_to_1d.h:41
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:33
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
fl::CRGB CRGB
Definition crgb.h:25
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:414
unsigned char uint8_t
Definition stdint.h:208
#define Serial
Definition serial.h:304
Aggregator header for the fl/ui/ family of per-element UI types.