FastLED 3.9.15
Loading...
Searching...
No Matches
Fire2012.ino
Go to the documentation of this file.
1// @filter: (board is not stm32f103cb) // Maple Mini lacks pin 5 (uses libmaple numbering)
5
6#include <FastLED.h>
7
8#define LED_PIN 5
9#define COLOR_ORDER GRB
10#define CHIPSET WS2811
11#define NUM_LEDS 30
12
13#define BRIGHTNESS 200
14#define FRAMES_PER_SECOND 60
15
16bool gReverseDirection = false;
17
19
20// Forward declaration
21void Fire2012();
22
23void setup() {
24 delay(3000); // sanity delay
25 FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
26 FastLED.setBrightness( BRIGHTNESS );
27}
28
29void loop()
30{
31 // Add entropy to random number generator; we use a lot of it.
33
34 Fire2012(); // run simulation frame
35
36 FastLED.show(); // display this frame
37 FastLED.delay(1000 / FRAMES_PER_SECOND);
38}
39
40
41// Fire2012 by Mark Kriegsman, July 2012
42// as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
44// This basic one-dimensional 'fire' simulation works roughly as follows:
45// There's a underlying array of 'heat' cells, that model the temperature
46// at each point along the line. Every cycle through the simulation,
47// four steps are performed:
48// 1) All cells cool down a little bit, losing heat to the air
49// 2) The heat from each cell drifts 'up' and diffuses a little
50// 3) Sometimes randomly new 'sparks' of heat are added at the bottom
51// 4) The heat from each cell is rendered as a color into the leds array
52// The heat-to-color mapping uses a black-body radiation approximation.
53//
54// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
55//
56// This simulation scales it self a bit depending on NUM_LEDS; it should look
57// "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
58//
59// I recommend running this simulation at anywhere from 30-100 frames per second,
60// meaning an interframe delay of about 10-35 milliseconds.
61//
62// Looks best on a high-density LED setup (60+ pixels/meter).
63//
64//
65// There are two main parameters you can play with to control the look and
66// feel of your fire: COOLING (used in step 1 above), and SPARKING (used
67// in step 3 above).
68//
69// COOLING: How much does the air cool as it rises?
70// Less cooling = taller flames. More cooling = shorter flames.
71// Default 50, suggested range 20-100
72#define COOLING 55
73
74// SPARKING: What chance (out of 255) is there that a new spark will be lit?
75// Higher chance = more roaring fire. Lower chance = more flickery fire.
76// Default 120, suggested range 50-200.
77#define SPARKING 120
78
79
81{
82// Array of temperature readings at each simulation cell
83 static uint8_t heat[NUM_LEDS];
84
85 // Step 1. Cool down every cell a little
86 for( int i = 0; i < NUM_LEDS; i++) {
87 heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
88 }
89
90 // Step 2. Heat from each cell drifts 'up' and diffuses a little
91 for( int k= NUM_LEDS - 1; k >= 2; k--) {
92 heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
93 }
94
95 // Step 3. Randomly ignite new 'sparks' of heat near the bottom
96 if( random8() < SPARKING ) {
97 int y = random8(7);
98 heat[y] = qadd8( heat[y], random8(160,255) );
99 }
100
101 // Step 4. Map from heat cells to LED colors
102 for( int j = 0; j < NUM_LEDS; j++) {
103 CRGB color = HeatColor( heat[j]);
104 int pixelnumber;
105 if( gReverseDirection ) {
106 pixelnumber = (NUM_LEDS-1) - j;
107 } else {
108 pixelnumber = j;
109 }
110 leds[pixelnumber] = color;
111 }
112}
void setup()
void loop()
#define COLOR_ORDER
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
#define LED_PIN
#define BRIGHTNESS
int y
Definition simple.h:93
#define CHIPSET
#define FRAMES_PER_SECOND
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
void Fire2012()
Definition Fire2012.ino:80
#define COOLING
Definition Fire2012.ino:72
#define SPARKING
Definition Fire2012.ino:77
bool gReverseDirection
Definition Fire2012.ino:16
uint8_t heat[NUM_LEDS]
Definition Fire2023.h:100
CRGB HeatColor(fl::u8 temperature)
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
fl::CRGB CRGB
Definition crgb.h:25
LIB8STATIC void random16_add_entropy(fl::u16 entropy) FL_NOEXCEPT
Add entropy into the random number generator.
Definition random8.h:110
LIB8STATIC fl::u16 random16() FL_NOEXCEPT
Generate a 16-bit random number.
Definition random8.h:63
LIB8STATIC fl::u8 random8() FL_NOEXCEPT
Generate an 8-bit random number.
Definition random8.h:53