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

◆ setup()

void setup ( )

Definition at line 290 of file curr.h.

290 {
291 // Use constexpr dimensions (computed at compile time)
292 constexpr int width = CORKSCREW_WIDTH; // = 16
293 constexpr int height = CORKSCREW_HEIGHT; // = 18
294
295
296 // Noise controls are now automatically grouped by the fl::UIGroup constructor
297 // The noiseGroup variadic constructor automatically called setGroup() on all controls
298
299
300 // Or use runtime corkscrew for dynamic sizing
301 // int width = corkscrew.cylinder_width();
302 // int height = corkscrew.cylinder_height();
303
305
306 // Use the corkscrew's internal buffer for the LED strip
308 &FastLED.addLeds<APA102HD, PIN_DATA, PIN_CLOCK, BGR>(corkscrew.rawData(), NUM_LEDS);
309
310 // CLEDController *controller =
311 // &FastLED.addLeds<WS2812, 3, BGR>(stripLeds, NUM_LEDS);
312
313 // NEW: Create fl::ScreenMap directly from fl::Corkscrew using toScreenMap()
314 // This maps each LED index to its exact position on the corkscrew spiral
315 // instead of using a rectangular grid mapping
316 fl::ScreenMap corkscrewScreenMap = corkscrew.toScreenMap(0.2f);
317
318 // OLD WAY (rectangular grid - not accurate for corkscrew visualization):
319 // fl::ScreenMap screenMap = xyMap.toScreenMap();
320 // screenMap.setDiameter(.2f);
321
322 // Set the corkscrew screen map for the controller
323 // This allows the web interface to display the actual corkscrew spiral shape
324 controller->setScreenMap(corkscrewScreenMap);
325
326 // Initialize wave effects for cylindrical surface
327 fl::XYMap xyRect(width, height, false); // Rectangular grid for wave simulation
328 fl::WaveFx::Args waveArgs;
329 waveArgs.factor = fl::SuperSample::SUPER_SAMPLE_2X; // 2x supersampling for smoother waves
330 waveArgs.half_duplex = true; // Only positive waves
331 waveArgs.auto_updates = true; // Auto-update simulation
332 waveArgs.speed = 0.16f; // Wave propagation speed
333 waveArgs.dampening = 6.0f; // Wave energy loss
334 waveArgs.x_cyclical = true; // Enable cylindrical wrapping!
335 waveArgs.crgbMap = fl::make_shared<fl::WaveCrgbGradientMap>(waveBluepal); // Default color palette
336
337 // Create wave effect with cylindrical mapping
338 waveFx = fl::make_shared<fl::WaveFx>(xyRect, waveArgs);
339
340 // Create blender for wave effects (allows multiple wave layers in future)
342 waveBlend->add(waveFx);
343
344 // Initialize fl::Animartrix effect
345 fl::XYMap animartrixXyMap = fl::XYMap::constructRectangularGrid(width, height, 0);
346 animartrix.reset(new fl::Animartrix(animartrixXyMap, fl::AnimartrixAnim::POLAR_WAVES)); // ok bare allocation
347 fxEngine.reset(new fl::FxEngine(width * height)); // ok bare allocation
348 fxEngine->addFx(*animartrix);
349
350 // Demonstrate fl::UIGroup functionality for noise controls
351 FL_WARN("Noise UI Group initialized: " << noiseGroup.name());
352 FL_WARN(" This group contains noise pattern controls:");
353 FL_WARN(" - Use Noise Pattern toggle");
354 FL_WARN(" - Noise Scale and Speed sliders");
355 FL_WARN(" - Color Palette selection for noise");
356 FL_WARN(" fl::UIGroup automatically applied group membership via variadic constructor");
357
358 // Set initial dropdown selections
359 paletteDropdown.setSelectedIndex(0); // Party
360 renderModeDropdown.setSelectedIndex(0); // Fire (new default)
361
362 // Add onChange callbacks for dropdowns
363 paletteDropdown.onChanged([](fl::UIDropdown &dropdown) {
364 fl::string selectedPalette = dropdown.value();
365 FL_WARN("Noise palette changed to: " << selectedPalette);
366 if (selectedPalette == "Party") {
368 } else if (selectedPalette == "Heat") {
370 } else if (selectedPalette == "Ocean") {
372 } else if (selectedPalette == "Forest") {
374 } else if (selectedPalette == "Rainbow") {
376 }
377 });
378
379 renderModeDropdown.onChanged([](fl::UIDropdown &dropdown) {
380 fl::string mode = dropdown.value();
381 // Simple example of using getOption()
382 for(size_t i = 0; i < dropdown.getOptionCount(); i++) {
383 if(dropdown.getOption(i) == mode) {
384 FL_WARN("Render mode changed to: " << mode);
385 }
386 }
387 });
388
389 // Add onChange callback for animartrix color order
390 animartrixColorOrder.onChanged([](int value) {
391 EOrder order = RGB;
392 switch(value) {
393 case 0: order = RGB; break;
394 case 1: order = RBG; break;
395 case 2: order = GRB; break;
396 case 3: order = GBR; break;
397 case 4: order = BRG; break;
398 case 5: order = BGR; break;
399 }
400 if (animartrix.get()) {
401 animartrix->setColorOrder(order);
402 }
403 });
404
405
406 waveFx->setCrgbMap(crgMap);
407
408 frameBufferPtr = corkscrew.getOrCreateInputSurface();
409}
fl::XYMap xyMap
fl::FxEngine fxEngine(NUM_LEDS)
#define NUM_LEDS
fl::Animartrix animartrix(xyMap, FIRST_ANIMATION)
#define PIN_DATA
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
Definition FastLED.h:267
CLEDController * controller
Manages and renders multiple visual effects (Fx) for LED strips.
Definition fx_engine.h:33
fl::string getOption(fl::size index) const FL_NOEXCEPT
Definition dropdown.h:135
fl::string value() const FL_NOEXCEPT
Definition dropdown.h:126
fl::size getOptionCount() const FL_NOEXCEPT
Definition dropdown.h:134
WaveFxArgs Args
Definition wave.h:168
static XYMap constructRectangularGrid(u16 width, u16 height, u16 offset=0) FL_NOEXCEPT
Definition xymap.cpp.hpp:35
fl::CLEDController CLEDController
fl::UIDropdown renderModeDropdown("Render Mode", renderModeOptions)
fl::WaveCrgbGradientMapPtr crgMap
Definition curr.h:288
fl::Blend2dPtr waveBlend
Definition curr.h:283
#define PIN_CLOCK
Definition curr.h:51
fl::CRGBPalette16 noisePalette
Definition curr.h:243
constexpr uint16_t CORKSCREW_HEIGHT
Definition curr.h:262
fl::shared_ptr< fl::Grid< fl::CRGB > > frameBufferPtr
Definition curr.h:279
fl::UIDropdown paletteDropdown("Color Palette", paletteOptions)
constexpr uint16_t CORKSCREW_WIDTH
Definition curr.h:260
UINumberField animartrixColorOrder("fl::Animartrix Color Order", 0, 0, 5)
fl::WaveFxPtr waveFx
Definition curr.h:282
fl::UIGroup noiseGroup("Noise Controls", noiseScale, noiseSpeed, paletteDropdown)
constexpr EOrder BGR
Definition eorder.h:22
constexpr EOrder RBG
Definition eorder.h:18
fl::EOrder EOrder
Definition eorder.h:12
constexpr EOrder BRG
Definition eorder.h:21
constexpr EOrder GRB
Definition eorder.h:19
constexpr EOrder RGB
Definition eorder.h:17
constexpr EOrder GBR
Definition eorder.h:20
fl::Corkscrew corkscrew(CORKSCREW_TURNS, NUM_LEDS)
const TProgmemRGBPalette16 OceanColors_p
Ocean colors, blues and whites.
const TProgmemRGBPalette16 HeatColors_p
Approximate "black body radiation" palette, akin to the FastLED HeatColor() function.
const TProgmemRGBPalette16 ForestColors_p
Forest colors, greens.
const TProgmemRGBPalette16 PartyColors_p
HSV color ramp: blue, purple, pink, red, orange, yellow (and back).
const TProgmemRGBPalette16 RainbowColors_p
HSV Rainbow.
#define FL_WARN(X)
Definition log.h:276
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
float speed
Wave propagation speed (0.0-1.0, typical: 0.1-0.3)
Definition wave.h:126
bool x_cyclical
If true, waves wrap around the x-axis (cylindrical topology)
Definition wave.h:130
WaveCrgbMapPtr crgbMap
Custom color mapper (nullptr uses default grayscale)
Definition wave.h:134
bool auto_updates
If true, simulation advances automatically in draw()
Definition wave.h:124
SuperSample factor
Supersampling quality (SUPER_SAMPLE_2X recommended for balance)
Definition wave.h:120
float dampening
Energy dampening factor (higher = faster decay, typical: 3-10)
Definition wave.h:128
bool half_duplex
If true, constrains waves to positive values only.
Definition wave.h:122

References animartrix, animartrixColorOrder(), APA102HD, fl::WaveFxArgs::auto_updates, BGR, BRG, fl::XYMap::constructRectangularGrid(), controller, corkscrew(), CORKSCREW_HEIGHT, CORKSCREW_WIDTH, fl::WaveFxArgs::crgbMap, crgMap, fl::WaveFxArgs::dampening, fl::WaveFxArgs::factor, FastLED, FL_WARN, ForestColors_p, frameBufferPtr, fxEngine, GBR, fl::UIDropdown::getOption(), fl::UIDropdown::getOptionCount(), GRB, fl::WaveFxArgs::half_duplex, HeatColors_p, fl::make_shared(), noiseGroup(), noisePalette, NUM_LEDS, OceanColors_p, paletteDropdown(), PartyColors_p, PIN_CLOCK, PIN_DATA, fl::POLAR_WAVES, RainbowColors_p, RBG, renderModeDropdown(), RGB, fl::WaveFxArgs::speed, fl::SUPER_SAMPLE_2X, fl::UIDropdown::value(), waveBlend, waveFx, fl::WaveFxArgs::x_cyclical, and xyMap.

+ Here is the call graph for this function: