FastLED 3.9.3
Loading...
Searching...
No Matches
Fire2012.ino
1
3// Fire2012 by Mark Kriegsman, July 2012
4// as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
6// This basic one-dimensional 'fire' simulation works roughly as follows:
7// There's a underlying array of 'heat' cells, that model the temperature
8// at each point along the line. Every cycle through the simulation,
9// four steps are performed:
10// 1) All cells cool down a little bit, losing heat to the air
11// 2) The heat from each cell drifts 'up' and diffuses a little
12// 3) Sometimes randomly new 'sparks' of heat are added at the bottom
13// 4) The heat from each cell is rendered as a color into the leds array
14// The heat-to-color mapping uses a black-body radiation approximation.
15//
16// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
17//
18// This simulation scales it self a bit depending on NUM_LEDS; it should look
19// "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
20//
21// I recommend running this simulation at anywhere from 30-100 frames per second,
22// meaning an interframe delay of about 10-35 milliseconds.
23//
24// Looks best on a high-density LED setup (60+ pixels/meter).
25//
26//
27// There are two main parameters you can play with to control the look and
28// feel of your fire: COOLING (used in step 1 above), and SPARKING (used
29// in step 3 above).
30//
31// COOLING: How much does the air cool as it rises?
32// Less cooling = taller flames. More cooling = shorter flames.
33// Default 50, suggested range 20-100
34
35// SPARKING: What chance (out of 255) is there that a new spark will be lit?
36// Higher chance = more roaring fire. Lower chance = more flickery fire.
37// Default 120, suggested range 50-200.
38
39#include <FastLED.h>
40#include "fx/1d/fire2012.hpp"
41
42#define LED_PIN 5
43#define COLOR_ORDER GRB
44#define CHIPSET WS2811
45#define NUM_LEDS 30
46
47#define BRIGHTNESS 128
48#define FRAMES_PER_SECOND 30
49#define COOLING 55
50#define SPARKING 120
51#define REVERSE_DIRECTION false
52
53CRGB leds[NUM_LEDS];
54Fire2012Ref fire = Fire2012Ref::New(NUM_LEDS, COOLING, SPARKING, REVERSE_DIRECTION);
55
56void setup() {
57 delay(3000); // sanity delay
58 FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
59 .setCorrection(TypicalLEDStrip)
60 .setRgbw();
61 FastLED.setBrightness(BRIGHTNESS);
62}
63
64void loop()
65{
66 fire->draw(Fx::DrawContext(millis(), leds)); // run simulation frame
67
68 FastLED.show(millis()); // display this frame
69 FastLED.delay(1000 / FRAMES_PER_SECOND);
70}
71
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:33
central include file for FastLED, defines the CFastLED class/object
void delay(unsigned long ms)
Delay for the given number of milliseconds.
Definition FastLED.cpp:178
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:722
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:82
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:67
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39