MCPcopy Create free account
hub / github.com/FastLED/FastLED / loop

Function loop

examples/FireCylinder/FireCylinder.h:173–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173void loop() {
174 // The main program loop that runs continuously
175
176 // Set the overall brightness from the UI slider
177 FastLED.setBrightness(brightness);
178
179 // Get the selected color palette
180 fl::CRGBPalette16 myPal = getPalette();
181
182 // Get the current time in milliseconds
183 uint32_t now = fl::millis();
184
185 // Update the animation speed from the UI slider
186 timeScale.setSpeed(speedY);
187
188 // Calculate the current y-offset for animation (makes the fire move)
189 uint32_t y_speed = timeScale.update(now);
190
191 // Loop through every LED in our cylindrical matrix
192 for (int width = 0; width < WIDTH; width++) {
193 for (int height = 0; height < HEIGHT; height++) {
194 // Calculate which color to use from our palette for this LED
195 // This function handles the cylindrical mapping using sine/cosine
196 uint8_t palette_index =
197 getPaletteIndex(now, width, WIDTH, height, HEIGHT, y_speed);
198
199 // Get the actual RGB color from the palette
200 // BRIGHTNESS ensures we use the full brightness range
201 fl::CRGB c = ColorFromPalette(myPal, palette_index, BRIGHTNESS);
202
203 // Convert our 2D coordinates to the 1D fl::array index
204 // We use (WIDTH-1)-width and (HEIGHT-1)-height to flip the coordinates
205 // This makes the fire appear to rise from the bottom
206 int index = xyMap((WIDTH - 1) - width, (HEIGHT - 1) - height);
207
208 // Set the LED color in our fl::array
209 leds[index] = c;
210 }
211 }
212
213 // Send the color data to the actual LEDs
214 FastLED.show();
215}

Callers

nothing calls this directly

Calls 8

ColorFromPaletteFunction · 0.85
getPaletteFunction · 0.70
getPaletteIndexFunction · 0.70
millisFunction · 0.50
setBrightnessMethod · 0.45
setSpeedMethod · 0.45
updateMethod · 0.45
showMethod · 0.45

Tested by

no test coverage detected