Advertisement
Guest User

FastLED / Fire2012 multizone animation

a guest
Apr 14th, 2015
1,201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. /*
  2. *
  3. Demo Code for FastLED and Fire2012 Animation to make it use separate actions on different pins
  4. with different number of LEDs if necessary.
  5. * Created: 3/17/2015 2:57:40 PM
  6. * Final mods: March 26 2015ish
  7. * Author: Dave Hrynkiw, Solarbotics Ltd.
  8. * Special thx to K. Lonney for assistance
  9. */
  10.  
  11. //* Adding FIRE animation trial
  12. #include <FastLED.h>
  13. #define BRIGHTNESS 200
  14. #define FRAMES_PER_SECOND 40
  15. #define SPARKING 10
  16. #define COOLING 30
  17.  
  18. //ZONE 1 DEFINITIONS
  19. #define Z1_DATAPIN 4 //Declare Zone 1 data pin
  20. #define Z1_LEDS 36 //Declare Zone 1 number of LEDs
  21. CRGB Z1[Z1_LEDS]; //Declare Zone 1 FastLED data array
  22. byte Z1_Heat[Z1_LEDS]; //Delcare Zone 1 Heat map data array
  23.  
  24. //ZONE 2 DEFINITIONS
  25. #define Z2_DATAPIN 5 //Declare Zone 2 data pin
  26. #define Z2_LEDS 36 //Declare Zone 2 number of LEDs
  27. CRGB Z2[Z2_LEDS]; //Declare Zone 2 FastLED data array
  28. byte Z2_Heat[Z2_LEDS]; //Delcare Zone 2 Heat map data array
  29.  
  30. CRGBPalette16 gPal; //Set pallet array
  31.  
  32. void setup()
  33. {
  34. delay(2000); //DON'T IGNORE THIS. Yes, it makes a difference, especially on a Teensy 3.1
  35. FastLED.addLeds<WS2812B, Z1_DATAPIN, GRB>(Z1, 0, Z1_LEDS); //Z1 Initialize the FastLED functions
  36. FastLED.addLeds<WS2812B, Z2_DATAPIN, GRB>(Z2, 0, Z2_LEDS); //Z1 Initialize the FastLED functions
  37.  
  38. FastLED.setBrightness(100); //Set global maximum brightness
  39. // This first palette is the basic 'black body radiation' colors,
  40. // which run from black to red to bright yellow to white.
  41. gPal = HeatColors_p;
  42.  
  43. // These are other ways to set up the color palette for the 'fire'.
  44. // First, a gradient from black to red to yellow to white -- similar to HeatColors_p
  45. // gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::Yellow, CRGB::White);
  46.  
  47. // Second, this palette is like the heat colors, but blue/aqua instead of red/yellow
  48. // gPal = CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White);
  49.  
  50. // Third, here's a simpler, three-step gradient, from black to red to white
  51. // gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::White);
  52.  
  53. // Davetest for a green pallet.
  54. // gPal = CRGBPalette16( CRGB::Black, CRGB::Green, CRGB::YellowGreen, CRGB::White);
  55.  
  56. }
  57.  
  58. void loop() {
  59.  
  60. // Add entropy to random number generator; we use a lot of it.
  61. random16_add_entropy( random());
  62. Fire2012(Z1_Heat, Z1, Z1_LEDS); //Call the Fire subroutine, passing the Heatmap, the Zone, and Number of LEDs
  63. Fire2012(Z2_Heat, Z2, Z2_LEDS);
  64. FastLED.show(); // display the frame
  65. FastLED.delay(1000 / FRAMES_PER_SECOND); //Slow that sucka down (esp. on a Teensy)
  66. }
  67.  
  68. void Fire2012(byte *heat, CRGB *leds, int number_leds) //Might not need the "*" in front of the arrays...
  69. {
  70. // Step 1. Cool down every cell a little
  71. for( int i = 0; i < number_leds; i++) {
  72. heat[i] = qsub8(heat[i], random8(0, ((COOLING * 10) / number_leds) + 2));
  73. }
  74.  
  75. // Step 2. Heat from each cell drifts 'up' and diffuses a little
  76. for( byte k= number_leds - 1; k >= 2; k--) {
  77. heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  78. }
  79.  
  80. // Step 3. Randomly ignite new 'sparks' of heat near the bottom
  81. if( random8() < SPARKING ) {
  82. int y = random8(7);
  83. heat[y] = qadd8( heat[y], random8(160,255) );
  84. }
  85.  
  86. // Step 4. Map from heat cells to LED colors
  87. for( int j = 0; j < number_leds; j++) {
  88. //leds[j] = HeatColor(heat[j]);
  89. byte colorindex = scale8( heat[number_leds-j], 240);
  90. leds[j] = ColorFromPalette( gPal, colorindex);
  91.  
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement