FastLED 3.9.15
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 FastLED.add(config);
96 FastLED.setBrightness(BRIGHTNESS);
97
98 // Group UI elements
99 enableAmbient.setGroup("Features");
100 enableMeteors.setGroup("Features");
101 enableTimeWarp.setGroup("Features");
102
103 meteorThreshold.setGroup("Audio Detection");
104 ambientThreshold.setGroup("Audio Detection");
105
106 dragSlider.setGroup("Physics");
107 speedSlider.setGroup("Physics");
108 minVelocitySlider.setGroup("Physics");
109
110 ambientTrailSlider.setGroup("Trails");
111 meteorTrailSlider.setGroup("Trails");
112 ambientDecaySlider.setGroup("Trails");
113 debrisDecaySlider.setGroup("Trails");
114 debrisVelDecaySlider.setGroup("Trails");
115
116 // Blue-white palettes
117 CRGBPalette16 bluePalette(CRGB(0, 0, 40), CRGB(0, 40, 120),
118 CRGB(100, 160, 255), CRGB(255, 255, 255));
119 sailboatFx.setNoisePalette(bluePalette);
120 sailboatFx.setAmbientPalette(bluePalette);
121 sailboatFx.setMeteorGradient(CRGB(255, 255, 255), // white-hot head
122 CRGB(140, 180, 255), // light blue mid
123 CRGB(0, 40, 120)); // deep blue tail
124
125 // Register effect with engine
126 fxEngine.addFx(sailboatFx);
127
128 // --- Wire up audio detector callbacks ---
129 // Uses the Vibe detector which self-normalizes bass levels:
130 // getVibeBass() ~1.0 = average for current song
131 // >1.0 = louder than average, <1.0 = quieter
132 // This approach works across all music volumes and styles.
133 auto audio = FastLED.add(audio_ui);
134 fxEngine.setAudio(audio); // delivers AudioBatch to effects via DrawContext
135 if (audio) {
136 // Called every frame with full vibe data — we do threshold
137 // checks here for both ambient and meteor spawning.
138 audio->onVibeLevels(
139 [&](const fl::audio::detector::VibeLevels &levels) {
140 float bass = levels.bass; // self-normalizing, ~1.0 avg
141
142 // Ambient: spawn on bass spikes above ambient threshold
143 if (enableAmbient && levels.bassSpike &&
144 bass > ambientThreshold.value()) {
145 // Scale intensity: map bass from threshold..threshold*2
146 // to 0.3..1.0
147 float thresh = ambientThreshold.value();
148 float intensity =
149 fl::clamp((bass - thresh) / thresh, 0.3f, 1.0f);
150 int count = 1 + int(intensity * 2.0f); // 1-3 particles
151 for (int i = 0; i < count; i++) {
152 sailboatFx.spawnAmbient(intensity);
153 }
154 }
155
156 // Meteor: spawn only on very strong bass hits
157 if (enableMeteors && levels.bassSpike &&
158 bass > meteorThreshold.value()) {
159 float thresh = meteorThreshold.value();
160 // Map bass from threshold..threshold*2 to 0.4..1.0
161 float intensity =
162 fl::clamp((bass - thresh) / thresh, 0.4f, 1.0f);
163 sailboatFx.spawnMeteor(intensity);
164 if (enableTimeWarp)
165 noiseTimeMultiplier = 1.0f + intensity * 2.0f;
166 }
167 });
168
169 // Drop detector: biggest moments (has built-in 2s cooldown)
170 audio->onDropImpact([&](float impact) {
171 if (enableMeteors)
172 sailboatFx.spawnMeteor(impact);
173 if (enableTimeWarp)
174 noiseTimeMultiplier = 2.0f + impact;
175 });
176 }
177}
#define COLOR_ORDER
fl::UIAudio audio("Audio Input")
fl::FxEngine fxEngine(NUM_LEDS)
#define NUM_LEDS
fl::CRGB leds[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_NOEXCEPT
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_NOEXCEPT
Configuration for a single LED channel.
Definition config.h:163
Optional channel configuration parameters All fields have sensible defaults and can be overridden as ...
Definition options.h:43
Clockless chipset configuration (single data pin)
Definition config.h:32
#define Serial
Definition serial.h:304

References ambientDecaySlider, ambientThreshold, ambientTrailSlider, audio, audio_ui, 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: