FastLED 3.9.15
Loading...
Searching...
No Matches

◆ loop()

void loop ( )

Definition at line 152 of file AnimartrixRing.ino.

152 {
153 // Manual audio pump fallback (e.g. WASM / when FastLED.add() didn't take).
154 if (!gAutoPump) {
156 if (sample.isValid() && enableOrchestrator.value()) {
157 gAudioProcessor->update(sample);
158 }
159 }
160
161 // Per-frame orchestrator tick. When disabled, fall back to plain manual
162 // speed so the sketch still behaves like a non-audio Animartrix demo.
163 if (enableOrchestrator.value()) {
164 // Apply UI overrides cheaply on every tick.
166 cfg.minDwellMs = static_cast<fl::u32>(orchestratorDwellMs.value());
168 static_cast<fl::u32>(orchestratorHysteresisMs.value());
169 gOrchestrator->setConfig(cfg);
170
171 const fl::u32 now = millis();
172 gOrchestrator->tick(now, timeSpeed.value());
173
174 // Log state transitions.
175 static animartrix_ring::SoundState sLast =
177 if (gOrchestrator->state() != sLast) {
178 sLast = gOrchestrator->state();
179 printf("AnimartrixRing: state -> %s (engine speed=%.2f)\n",
181 gOrchestrator->lastEngineSpeed());
182 }
183 } else {
184 fxEngine.setSpeed(timeSpeed.value());
185 }
186
187 // Draw the effect
188 fxEngine.draw(millis(), leds);
189
190 // Calculate final brightness
191 uint8_t finalBrightness;
192 if (autoBrightness.value()) {
193 float avgBri = getAverageBrightness(leds, NUM_LEDS);
194 finalBrightness = applyBrightnessCompression(
195 avgBri, static_cast<uint8_t>(autoBrightnessMax.value()),
198 } else {
199 finalBrightness = static_cast<uint8_t>(brightness.value());
200 }
201
202 FastLED.setBrightness(finalBrightness);
203 FastLED.show();
204}
fl::UIAudio audio("Audio Input")
fl::FxEngine fxEngine(NUM_LEDS)
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
fl::UISlider timeSpeed("Time Speed", 1, -10, 10,.1)
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
fl::UISlider orchestratorHysteresisMs("Orchestrator Hysteresis (ms)", 400, 0, 2000, 50)
fl::UICheckbox enableOrchestrator("Enable Sound Orchestrator", false)
bool gAutoPump
fl::shared_ptr< animartrix_ring::SoundOrchestrator > gOrchestrator
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::shared_ptr< fl::audio::Processor > gAudioProcessor
fl::UISlider orchestratorDwellMs("Orchestrator Min Dwell (ms)", 1500, 200, 5000, 100)
fl::UISlider autoBrightnessMax("Auto Brightness Max", 84, 0, 255, 1)
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
uint8_t applyBrightnessCompression(float inputBrightnessPercent, uint8_t maxBrightness, float lowThreshold, float highThreshold)
float getAverageBrightness(CRGB *leds, int numLeds)
const char * toString(SoundState s)
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
void printf(const char *format, const Args &... args) FL_NOEXCEPT
Printf-like formatting function that prints directly to the platform output.
Definition stdio.h:635
CRGB sample(const CRGB *grid, const XYMap &xyMap, float x, float y, SampleMode mode)
Sample a pixel from a 2D CRGB grid at floating-point coordinates.
Definition sample.cpp.hpp:9
unsigned char uint8_t
Definition s16x16x4.h:209

References applyBrightnessCompression(), audio, autoBrightness, autoBrightnessHighThreshold, autoBrightnessLowThreshold, autoBrightnessMax, brightness, animartrix_ring::OrchestratorConfig::classifierHysteresisMs, enableOrchestrator, FastLED, fxEngine, gAudioProcessor, gAutoPump, getAverageBrightness(), gOrchestrator, leds, animartrix_ring::OrchestratorConfig::minDwellMs, NUM_LEDS, orchestratorDwellMs, orchestratorHysteresisMs, animartrix_ring::Silence, timeSpeed, and animartrix_ring::toString().

+ Here is the call graph for this function: