// Source: https://github.com/s-marley/FastLED-basics
#include <FastLED.h>
#define NUM_LEDS 100
#define LED_PIN 2
#define COOLING 0
#define SPARKING 0
#define DIRECTION 0
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(50);
}
void loop() {
fireEffect();
FastLED.show();
delay(50); // Adjust the speed of the fire effect by changing the delay value
}
void fireEffect() {
static byte heat[NUM_LEDS];
// Step 1. Cool down every cell a little
for (int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8(heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for (int k = NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
}
// Step 3. Randomly ignite new 'sparks' near the bottom
if (random8() < SPARKING) {
int y = random8(7);
heat[y] = qadd8(heat[y], random8(160, 255));
}
// Step 4. Map from heat cells to LED colors
for (int j = 0; j < NUM_LEDS; j++) {
CRGB color = HeatColor(heat[j]);
int pixelnumber;
if (DIRECTION == 0) {
pixelnumber = j;
} else {
pixelnumber = (NUM_LEDS - 1) - j;
}
leds[pixelnumber] = color;
}
}