Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- Demo Code for FastLED and Fire2012 Animation to make it use separate actions on different pins
- with different number of LEDs if necessary.
- * Created: 3/17/2015 2:57:40 PM
- * Final mods: March 26 2015ish
- * Author: Dave Hrynkiw, Solarbotics Ltd.
- * Special thx to K. Lonney for assistance
- */
- //* Adding FIRE animation trial
- #include <FastLED.h>
- #define BRIGHTNESS 200
- #define FRAMES_PER_SECOND 40
- #define SPARKING 10
- #define COOLING 30
- //ZONE 1 DEFINITIONS
- #define Z1_DATAPIN 4 //Declare Zone 1 data pin
- #define Z1_LEDS 36 //Declare Zone 1 number of LEDs
- CRGB Z1[Z1_LEDS]; //Declare Zone 1 FastLED data array
- byte Z1_Heat[Z1_LEDS]; //Delcare Zone 1 Heat map data array
- //ZONE 2 DEFINITIONS
- #define Z2_DATAPIN 5 //Declare Zone 2 data pin
- #define Z2_LEDS 36 //Declare Zone 2 number of LEDs
- CRGB Z2[Z2_LEDS]; //Declare Zone 2 FastLED data array
- byte Z2_Heat[Z2_LEDS]; //Delcare Zone 2 Heat map data array
- CRGBPalette16 gPal; //Set pallet array
- void setup()
- {
- delay(2000); //DON'T IGNORE THIS. Yes, it makes a difference, especially on a Teensy 3.1
- FastLED.addLeds<WS2812B, Z1_DATAPIN, GRB>(Z1, 0, Z1_LEDS); //Z1 Initialize the FastLED functions
- FastLED.addLeds<WS2812B, Z2_DATAPIN, GRB>(Z2, 0, Z2_LEDS); //Z1 Initialize the FastLED functions
- FastLED.setBrightness(100); //Set global maximum brightness
- // This first palette is the basic 'black body radiation' colors,
- // which run from black to red to bright yellow to white.
- gPal = HeatColors_p;
- // These are other ways to set up the color palette for the 'fire'.
- // First, a gradient from black to red to yellow to white -- similar to HeatColors_p
- // gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::Yellow, CRGB::White);
- // Second, this palette is like the heat colors, but blue/aqua instead of red/yellow
- // gPal = CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White);
- // Third, here's a simpler, three-step gradient, from black to red to white
- // gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::White);
- // Davetest for a green pallet.
- // gPal = CRGBPalette16( CRGB::Black, CRGB::Green, CRGB::YellowGreen, CRGB::White);
- }
- void loop() {
- // Add entropy to random number generator; we use a lot of it.
- random16_add_entropy( random());
- Fire2012(Z1_Heat, Z1, Z1_LEDS); //Call the Fire subroutine, passing the Heatmap, the Zone, and Number of LEDs
- Fire2012(Z2_Heat, Z2, Z2_LEDS);
- FastLED.show(); // display the frame
- FastLED.delay(1000 / FRAMES_PER_SECOND); //Slow that sucka down (esp. on a Teensy)
- }
- void Fire2012(byte *heat, CRGB *leds, int number_leds) //Might not need the "*" in front of the arrays...
- {
- // Step 1. Cool down every cell a little
- for( int i = 0; i < number_leds; i++) {
- heat[i] = qsub8(heat[i], random8(0, ((COOLING * 10) / number_leds) + 2));
- }
- // Step 2. Heat from each cell drifts 'up' and diffuses a little
- for( byte k= number_leds - 1; k >= 2; k--) {
- heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
- }
- // Step 3. Randomly ignite new 'sparks' of heat near the bottom
- if( random8() < SPARKING ) {
- int y = random8(7);
- heat[y] = qadd8( heat[y], random8(160,255) );
- }
- // Step 4. Map from heat cells to LED colors
- for( int j = 0; j < number_leds; j++) {
- //leds[j] = HeatColor(heat[j]);
- byte colorindex = scale8( heat[number_leds-j], 240);
- leds[j] = ColorFromPalette( gPal, colorindex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement