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

◆ loop()

void loop ( )

Definition at line 158 of file FireMatrix.h.

158 {
159 // The main program loop that runs continuously
160
161 // Set the overall brightness from the UI slider
162 FastLED.setBrightness(brightness);
163
164 // Get the selected color palette
165 CRGBPalette16 myPal = getPalette();
166
167 // Get the current time in milliseconds
168 uint32_t now = millis();
169
170 // Update the animation speed from the UI slider
171 timeScale.setSpeed(speedY);
172
173 // Calculate the current y-offset for animation (makes the fire move)
174 uint32_t y_speed = timeScale.update(now);
175
176 // Loop through every LED in our matrix
177 for (int i = 0; i < WIDTH; i++) {
178 for (int j = 0; j < HEIGHT; j++) {
179 // Calculate which color to use from our palette for this LED
180 uint8_t palette_index = getPaletteIndex(now, i, j, y_speed);
181
182 // Get the actual RGB color from the palette
183 // BRIGHTNESS ensures we use the full brightness range
184 CRGB c = ColorFromPalette(myPal, palette_index, BRIGHTNESS);
185
186 // Convert our 2D coordinates (i,j) to the 1D array index
187 // We use (WIDTH-1)-i and (HEIGHT-1)-j to flip the coordinates
188 // This makes the fire appear to rise from the bottom
189 int index = xyMap((WIDTH - 1) - i, (HEIGHT - 1) - j);
190
191 // Set the LED color in our array
192 leds[index] = c;
193 }
194 }
195
196 // Send the color data to the actual LEDs
197 FastLED.show();
198}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define WIDTH
Definition Blur2d.ino:9
#define HEIGHT
Definition Blur2d.ino:10
#define BRIGHTNESS
Definition Blur.ino:8
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:62
TimeWarp timeScale(0, 1.0f)
UISlider speedY("SpeedY", 1.3, 1, 6,.1)
CRGBPalette16 getPalette()
Definition FireMatrix.h:144
uint8_t getPaletteIndex(uint32_t millis32, int i, int j, uint32_t y_speed)
Definition FireMatrix.h:115
UISlider brightness("Brightness", 1, 0, 1)
int y_speed
XYMap xyMap
Definition gfx.cpp:8
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55

References BRIGHTNESS, brightness, fl::ColorFromPalette(), FastLED, getPalette(), getPaletteIndex(), HEIGHT, leds, speedY(), timeScale(), WIDTH, xyMap, and y_speed.

+ Here is the call graph for this function: