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

◆ Fire2012WithPalette()

void Fire2012WithPalette ( )
Examples
Fire2012WithPalette.ino.

Definition at line 60 of file Fire2012WithPalette.ino.

61{
62// Array of temperature readings at each simulation cell
63 static uint8_t heat[NUM_LEDS];
64
65 // Step 1. Cool down every cell a little
66 for( int i = 0; i < NUM_LEDS; i++) {
67 heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
68 }
69
70 // Step 2. Heat from each cell drifts 'up' and diffuses a little
71 for( int k= NUM_LEDS - 1; k >= 2; k--) {
72 heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
73 }
74
75 // Step 3. Randomly ignite new 'sparks' of heat near the bottom
76 if( random8() < SPARKING ) {
77 int y = random8(7);
78 heat[y] = qadd8( heat[y], random8(160,255) );
79 }
80
81 // Step 4. Map from heat cells to LED colors
82 for( int j = 0; j < NUM_LEDS; j++) {
83 // Scale the heat value from 0-255 down to 0-240
84 // for best results with color palettes.
85 uint8_t colorindex = scale8( heat[j], 240);
86 CRGB color = ColorFromPalette( gPal, colorindex);
87 int pixelnumber;
88 if( gReverseDirection ) {
89 pixelnumber = (NUM_LEDS-1) - j;
90 } else {
91 pixelnumber = j;
92 }
93 leds[pixelnumber] = color;
94 }
95}
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
CRGBPalette16 gPal
uint8_t heat[NUM_LEDS]
Definition Fire2023.ino:89
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
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
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
Get a color from a palette.
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:44
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Definition scale8.h:34
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54

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

Referenced by loop().

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