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

◆ loop()

void loop ( )

Definition at line 156 of file FireMatrix.h.

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

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

+ Here is the call graph for this function: