FastLED 3.10.10
Loading...
Searching...
No Matches

◆ setup()

void setup ( )

Definition at line 86 of file Sailboat.ino.

86 {
87 Serial.begin(115200);
88 //FastLED.setExclusiveDriver(fl::Bus::SPI);
92 fl::ClocklessChipset chipset(DATA_PIN, timing);
94 config.setScreenMap(screenMap);
95 // Link only the platform's default clockless driver for add(cfg).
96 FastLED.enable<fl::Bus::AUTO>();
97 FastLED.add(config);
98 FastLED.setBrightness(BRIGHTNESS);
99
100 // Group UI elements
101 enableAmbient.setGroup("Features");
102 enableMeteors.setGroup("Features");
103 enableTimeWarp.setGroup("Features");
104
105 meteorThreshold.setGroup("Audio Detection");
106 ambientThreshold.setGroup("Audio Detection");
107
108 dragSlider.setGroup("Physics");
109 speedSlider.setGroup("Physics");
110 minVelocitySlider.setGroup("Physics");
111
112 ambientTrailSlider.setGroup("Trails");
113 meteorTrailSlider.setGroup("Trails");
114 ambientDecaySlider.setGroup("Trails");
115 debrisDecaySlider.setGroup("Trails");
116 debrisVelDecaySlider.setGroup("Trails");
117
118 // Blue-white palettes
119 CRGBPalette16 bluePalette(CRGB(0, 0, 40), CRGB(0, 40, 120),
120 CRGB(100, 160, 255), CRGB(255, 255, 255));
121 sailboatFx.setNoisePalette(bluePalette);
122 sailboatFx.setAmbientPalette(bluePalette);
123 sailboatFx.setMeteorGradient(CRGB(255, 255, 255), // white-hot head
124 CRGB(140, 180, 255), // light blue mid
125 CRGB(0, 40, 120)); // deep blue tail
126
127 // Register effect with engine
128 fxEngine.addFx(sailboatFx);
129
130 // --- Wire up audio detector callbacks ---
131 // Uses the Vibe detector which self-normalizes bass levels:
132 // getVibeBass() ~1.0 = average for current song
133 // >1.0 = louder than average, <1.0 = quieter
134 // This approach works across all music volumes and styles.
135 auto audio = FastLED.add(audio_ui);
136 fxEngine.setAudio(audio); // delivers AudioBatch to effects via DrawContext
137 if (audio) {
138 // Called every frame with full vibe data — we do threshold
139 // checks here for both ambient and meteor spawning.
140 audio->onVibeLevels(
141 [&](const fl::audio::detector::VibeLevels &levels) {
142 float bass = levels.bass; // self-normalizing, ~1.0 avg
143
144 // Ambient: spawn on bass spikes above ambient threshold
145 if (enableAmbient && levels.bassSpike &&
146 bass > ambientThreshold.value()) {
147 // Scale intensity: map bass from threshold..threshold*2
148 // to 0.3..1.0
149 float thresh = ambientThreshold.value();
150 float intensity =
151 fl::clamp((bass - thresh) / thresh, 0.3f, 1.0f);
152 int count = 1 + int(intensity * 2.0f); // 1-3 particles
153 for (int i = 0; i < count; i++) {
154 sailboatFx.spawnAmbient(intensity);
155 }
156 }
157
158 // Meteor: spawn only on very strong bass hits
159 if (enableMeteors && levels.bassSpike &&
160 bass > meteorThreshold.value()) {
161 float thresh = meteorThreshold.value();
162 // Map bass from threshold..threshold*2 to 0.4..1.0
163 float intensity =
164 fl::clamp((bass - thresh) / thresh, 0.4f, 1.0f);
165 sailboatFx.spawnMeteor(intensity);
166 if (enableTimeWarp)
167 noiseTimeMultiplier = 1.0f + intensity * 2.0f;
168 }
169 });
170
171 // Drop detector: biggest moments (has built-in 2s cooldown)
172 audio->onDropImpact([&](float impact) {
173 if (enableMeteors)
174 sailboatFx.spawnMeteor(impact);
175 if (enableTimeWarp)
176 noiseTimeMultiplier = 2.0f + impact;
177 });
178 }
179}
CRGB leds[1]
#define COLOR_ORDER
fl::UIAudio audio("Audio Input")
fl::FxEngine fxEngine(NUM_LEDS)
#define NUM_LEDS
#define BRIGHTNESS
#define DATA_PIN
Definition ClientReal.h:82
fl::UIAudio audio_ui("Audio Input")
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::UISlider speedSlider("Particle Speed", 2.6f, 0.1f, 3.0f, 0.1f)
fl::UICheckbox enableMeteors("Beat Meteors", true)
fl::UISlider ambientTrailSlider("Ambient Trail", 217.0f, 0.0f, 255.0f, 1.0f)
fl::UISlider minVelocitySlider("Min Velocity", 0.01f, 0.01f, 0.5f, 0.01f)
fl::UICheckbox enableAmbient("Ambient Particles", true)
fl::UISlider ambientDecaySlider("Ambient Fade", 0.955f, 0.90f, 1.0f, 0.005f)
fl::UICheckbox enableTimeWarp("Noise Time-Warp", false)
fl::UISlider debrisVelDecaySlider("Debris Drag", 0.95f, 0.85f, 1.0f, 0.01f)
float noiseTimeMultiplier
Definition Sailboat.ino:68
fl::UISlider dragSlider("Particle Drag", 0.06f, 0.0f, 1.0f, 0.01f)
fl::UISlider meteorTrailSlider("Meteor Trail", 171.0f, 0.0f, 255.0f, 1.0f)
fl::UISlider debrisDecaySlider("Debris Fade", 0.96f, 0.80f, 1.0f, 0.01f)
fl::UISlider meteorThreshold("Meteor Threshold", 1.5f, 1.5f, 6.0f, 0.1f)
fl::PerlinParticlePunch sailboatFx(NUM_LEDS)
fl::UISlider ambientThreshold("Ambient Threshold", 1.0f, 0.5f, 3.0f, 0.1f)
fl::ScreenMap screenMap
Definition Corkscrew.h:101
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
fl::CRGB CRGB
Definition crgb.h:25
constexpr ChipsetTimingConfig makeTimingConfig() FL_NO_EXCEPT
Convert compile-time CHIPSET type to runtime timing config.
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NO_EXCEPT
@ AUTO
Definition bus.h:32
Configuration for a single LED channel.
Definition config.h:167
Optional channel configuration parameters All fields have sensible defaults and can be overridden as ...
Definition options.h:93
Clockless chipset configuration (single data pin)
Definition config.h:33
#define Serial
Definition serial.h:314

References ambientDecaySlider, ambientThreshold, ambientTrailSlider, audio, audio_ui, fl::AUTO, fl::audio::detector::VibeLevels::bass, fl::audio::detector::VibeLevels::bassSpike, BRIGHTNESS, fl::clamp(), COLOR_ORDER, DATA_PIN, debrisDecaySlider, debrisVelDecaySlider, dragSlider, enableAmbient, enableMeteors, enableTimeWarp, FastLED, fxEngine, leds, fl::makeTimingConfig(), fl::ChannelOptions::mCorrection, meteorThreshold, meteorTrailSlider, minVelocitySlider, noiseTimeMultiplier, NUM_LEDS, sailboatFx, screenMap, Serial, fl::ChannelConfig::setScreenMap(), speedSlider, and TypicalLEDStrip.

+ Here is the call graph for this function: