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

◆ loop()

void loop ( )

Definition at line 144 of file FireMatrix.ino.

144 {
145 // The main program loop that runs continuously
146
147 // Set the overall brightness from the UI slider
148 FastLED.setBrightness(brightness);
149
150 // Get the selected color palette
151 CRGBPalette16 myPal = getPalette();
152
153 // Get the current time in milliseconds
154 uint32_t now = millis();
155
156 // Update the animation speed from the UI slider
157 timeScale.setSpeed(speedY);
158
159 // Calculate the current y-offset for animation (makes the fire move)
160 uint32_t y_speed = timeScale.update(now);
161
162 // Loop through every LED in our matrix
163 for (int i = 0; i < HEIGHT; i++) {
164 for (int j = 0; j < WIDTH; j++) {
165 // Calculate which color to use from our palette for this LED
166 uint8_t palette_index = getPaletteIndex(now, i, j, y_speed);
167
168 // Get the actual RGB color from the palette
169 // BRIGHTNESS ensures we use the full brightness range
170 CRGB c = ColorFromPalette(myPal, palette_index, BRIGHTNESS);
171
172 // Convert our 2D coordinates (i,j) to the 1D array index
173 // We use (HEIGHT-1)-i and (WIDTH-1)-j to flip the coordinates
174 // This makes the fire appear to rise from the bottom
175 int index = xyMap((HEIGHT - 1) - i, (WIDTH - 1) - j);
176
177 // Set the LED color in our array
178 leds[index] = c;
179 }
180 }
181
182 // Send the color data to the actual LEDs
183 FastLED.show();
184}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define WIDTH
Definition Audio.ino:33
#define HEIGHT
Definition Audio.ino:32
#define BRIGHTNESS
Definition Blur.ino:8
CFastLED FastLED
Global LED strip management instance.
UISlider speedY("SpeedY", 1.3, 1, 6,.1)
TimeWarp timeScale(0, 1.0f)
UISlider brightness("Brightness", 255, 0, 255, 1)
CRGBPalette16 getPalette()
uint8_t getPaletteIndex(uint32_t millis32, int i, int j, uint32_t y_speed)
XYMap xyMap(HEIGHT, WIDTH, SERPENTINE)
int y_speed
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: