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

◆ Fire2012WithPalette()

void Fire2012WithPalette ( )
Examples
Fire2012WithPalette.ino.

Definition at line 62 of file Fire2012WithPalette.ino.

63{
64// Array of temperature readings at each simulation cell
65 static uint8_t heat[NUM_LEDS];
66
67 // Step 1. Cool down every cell a little
68 for( int i = 0; i < NUM_LEDS; i++) {
69 heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
70 }
71
72 // Step 2. Heat from each cell drifts 'up' and diffuses a little
73 for( int k= NUM_LEDS - 1; k >= 2; k--) {
74 heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
75 }
76
77 // Step 3. Randomly ignite new 'sparks' of heat near the bottom
78 if( random8() < SPARKING ) {
79 int y = random8(7);
80 heat[y] = qadd8( heat[y], random8(160,255) );
81 }
82
83 // Step 4. Map from heat cells to LED colors
84 for( int j = 0; j < NUM_LEDS; j++) {
85 // Scale the heat value from 0-255 down to 0-240
86 // for best results with color palettes.
87 uint8_t colorindex = scale8( heat[j], 240);
88 CRGB color = ColorFromPalette( gPal, colorindex);
89 int pixelnumber;
90 if( gReverseDirection ) {
91 pixelnumber = (NUM_LEDS-1) - j;
92 } else {
93 pixelnumber = j;
94 }
95 leds[pixelnumber] = color;
96 }
97}
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
#define COOLING
Definition Fire2012.ino:72
#define SPARKING
Definition Fire2012.ino:77
bool gReverseDirection
Definition Fire2012.ino:16
CRGBPalette16 gPal
uint8_t heat[NUM_LEDS]
Definition Fire2023.h:100
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
fl::CRGB CRGB
Definition crgb.h:25
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
Definition random8.h:53
unsigned char uint8_t
Definition s16x16x4.h:209

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

Referenced by loop().

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