Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 3
- #define COLOR_ORDER GRB
- #define CHIPSET WS2812B
- #define NUM_LEDS 5
- #define NUM_COLS 12
- #define TOT_LEDS NUM_COLS*NUM_LEDS
- #define BRIGHTNESS 200
- #define FRAMES_PER_SECOND 30
- #define COOLING 55
- #define SPARKING 120
- CRGB leds[TOT_LEDS];
- void setup() {
- delay(3000); // sanity delay
- FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, TOT_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- // Serial.begin(9600);
- }
- void loop()
- {
- // Add entropy to random number generator; we use a lot of it.
- random16_add_entropy( random());
- Fire2012(); // run simulation frame
- FastLED.show(); // display this frame
- FastLED.delay(1000 / FRAMES_PER_SECOND);
- }
- void Fire2012()
- {
- // Array of temperature readings at each simulation cell
- static byte heat[TOT_LEDS];
- for ( int C = 0; C < NUM_COLS; C++) {
- // Serial.println(C);
- // Step 1. Cool down every cell a little
- for( int i = 0; i < NUM_LEDS; i++) {
- heat[i + C] = qsub8( heat[i + C], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
- }
- // Step 2. Heat from each cell drifts 'up' and diffuses a little
- for( int k= NUM_LEDS - 1; k >= 2; k--) {
- heat[k + C] = (heat[k - 1 + C] + heat[k - 2 + C] + heat[k - 2 + C] ) / 3;
- }
- // Step 3. Randomly ignite new 'sparks' of heat near the bottom
- if( random8() < SPARKING ) {
- int y = random8(7);
- heat[y + C] = qadd8( heat[y + C], random8(160,255) );
- }
- }
- // Step 4. Map from heat cells to LED colors
- for( int j = 0; j < TOT_LEDS; j++) {
- leds[j] = HeatColor( heat[j]);
- }
- }
Add Comment
Please, Sign In to add comment