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.
- * original sketch:
- * 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
- * modified by J. Bruegl, May 2015
- */
- //* Adding FIRE animation trial
- #include <FastLED.h>
- #define BRIGHTNESS 64 //200
- #define FRAMES_PER_SECOND 40
- #define SPARKING 18 // lower values calm fire down
- #define COOLING 50
- //ZONE 1 DEFINITIONS
- #define Z1_DATA_PIN 5 // Declare Zone 1 data pin
- #define Z1_CLOCK_PIN // Declare Zone 1 clock pin
- #define Z1_NUM_LEDS 44 // Declare Zone 1 number of LEDs
- CRGB Z1[Z1_NUM_LEDS]; // Declare Zone 1 FastLED data array
- byte Z1_Heat[Z1_NUM_LEDS]; // Delcare Zone 1 Heat map data array
- //ZONE 2 DEFINITIONS
- #define Z2_DATA_PIN 6 // Declare Zone 2 data pin
- #define Z2_CLOCK_PIN // Declare Zone 2 clock pin
- #define Z2_NUM_LEDS 44 // Declare Zone 2 number of LEDs
- CRGB Z2[Z2_NUM_LEDS]; // Declare Zone 2 FastLED data array
- byte Z2_Heat[Z2_NUM_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<NEOPIXEL, Z1_DATA_PIN>(Z1, 0, Z1_NUM_LEDS); //Z1 Initialize the FastLED functions
- FastLED.addLeds<NEOPIXEL, Z2_DATA_PIN>(Z2, 0, Z2_NUM_LEDS); //Z2 Initialize the FastLED functions
- // FastLED.addLeds<APA102, Z1_DATA_PIN, Z1_CLOCK_PIN>(Z1, 0, Z1_NUM_LEDS); //Z1 Initialize the FastLED functions
- // FastLED.addLeds<APA102, Z2_DATA_PIN, Z2_CLOCK_PIN>(Z2, 0, Z2_NUM_LEDS); //Z2 Initialize the FastLED functions
- FastLED.setBrightness(64); //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());
- // ----------------------------------------------------------------------------
- // This one sets up a new palette every time through the loop,
- // based on a hue that changes every time.
- // The palette is a gradient from black, to a dark color based on the hue,
- // to a light color based on the hue, to white.
- //
- /* start extra
- static uint8_t hue = 0;
- hue++;
- CRGB darkcolor = CHSV(hue,255,192); // pure hue, three-quarters brightness
- CRGB lightcolor = CHSV(hue,128,255); // half 'whitened', full brightness
- gPal = CRGBPalette16( CRGB::Black, darkcolor, lightcolor, CRGB::White);
- // end extra --------------------------------------------------------------------*/
- Fire2012(Z1_Heat, Z1, Z1_NUM_LEDS); // Call the Fire subroutine, passing the Heatmap,
- Fire2012(Z2_Heat, Z2, Z2_NUM_LEDS); // the Zone, and Number of 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); // this makes the thing upside down (!)
- byte colorindex = scale8( heat[j], 240);
- leds[j] = ColorFromPalette( gPal, colorindex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement