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

◆ Fire2012WithPalette()

void Fire2012WithPalette ( )
Examples
Fire2012WithPalette.ino.

Definition at line 61 of file Fire2012WithPalette.ino.

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

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: