FastLED 3.9.7
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
42using namespace fl;
43
44#define LED_PIN 5
45#define COLOR_ORDER GRB
46#define CHIPSET WS2811
47#define NUM_LEDS 30
48
49#define BRIGHTNESS 128
50#define FRAMES_PER_SECOND 30
51#define COOLING 55
52#define SPARKING 120
53#define REVERSE_DIRECTION false
54
55CRGB leds[NUM_LEDS];
56Fire2012Ptr fire = Fire2012Ptr::New(NUM_LEDS, COOLING, SPARKING, REVERSE_DIRECTION);
57
58void setup() {
59 delay(3000); // sanity delay
60 FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS)
61 .setCorrection(TypicalLEDStrip)
62 .setRgbw();
63 FastLED.setBrightness(BRIGHTNESS);
64}
65
66void loop()
67{
68 fire->draw(Fx::DrawContext(millis(), leds)); // run simulation frame
69
70 FastLED.show(millis()); // display this frame
71 FastLED.delay(1000 / FRAMES_PER_SECOND);
72}
73
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:45
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:190
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:723
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:94
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:79
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:19
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54