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

◆ Fire2012()

void Fire2012 ( )
Examples
Fire2012.ino.

Definition at line 76 of file Fire2012.ino.

77{
78// Array of temperature readings at each simulation cell
79 static uint8_t heat[NUM_LEDS];
80
81 // Step 1. Cool down every cell a little
82 for( int i = 0; i < NUM_LEDS; i++) {
83 heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
84 }
85
86 // Step 2. Heat from each cell drifts 'up' and diffuses a little
87 for( int k= NUM_LEDS - 1; k >= 2; k--) {
88 heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
89 }
90
91 // Step 3. Randomly ignite new 'sparks' of heat near the bottom
92 if( random8() < SPARKING ) {
93 int y = random8(7);
94 heat[y] = qadd8( heat[y], random8(160,255) );
95 }
96
97 // Step 4. Map from heat cells to LED colors
98 for( int j = 0; j < NUM_LEDS; j++) {
99 CRGB color = HeatColor( heat[j]);
100 int pixelnumber;
101 if( gReverseDirection ) {
102 pixelnumber = (NUM_LEDS-1) - j;
103 } else {
104 pixelnumber = j;
105 }
106 leds[pixelnumber] = color;
107 }
108}
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
#define NUM_LEDS
Definition Apa102.ino:6
#define COOLING
Definition Fire2012.ino:68
#define SPARKING
Definition Fire2012.ino:73
bool gReverseDirection
Definition Fire2012.ino:15
uint8_t heat[NUM_LEDS]
Definition Fire2023.ino:89
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
CRGB HeatColor(uint8_t temperature)
Approximates a "black body radiation" spectrum for a given "heat" level.
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
Definition math8.h:31
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
Definition math8.h:103
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:44
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54

References COOLING, gReverseDirection, heat, HeatColor(), leds, NUM_LEDS, qadd8(), qsub8(), random8(), SPARKING, and y.

Referenced by loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: