terrag42

FastLED Fire2012 X2 effect (not working)

Dec 18th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define CLOCK_PIN     D2
  4. #define DATA_PIN     D3
  5. #define COLOR_ORDER BGR
  6. #define CHIPSET     APA102
  7. #define NUM_LEDS_X2    60
  8. #define NUM_LEDS       30
  9.  
  10. #define BRIGHTNESS  50
  11. #define FRAMES_PER_SECOND 100
  12.  
  13. bool gReverseDirection = false;
  14.  
  15. CRGB leds[NUM_LEDS];
  16.  
  17. void setup() {
  18.   Serial.begin(115200);
  19.   delay(3000); // sanity delay
  20.   FastLED.addLeds<CHIPSET, DATA_PIN,CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS_X2).setCorrection( TypicalLEDStrip );
  21.   FastLED.setBrightness( BRIGHTNESS );
  22. }
  23.  
  24. void loop()
  25. {
  26.   // Add entropy to random number generator; we use a lot of it.
  27.   // random16_add_entropy( random());
  28.   Fire2012(); // run first half of simulation frame
  29.   FastLED.show(); // display this frame
  30.   FastLED.delay(1000 / FRAMES_PER_SECOND);
  31. }
  32.  
  33. #define COOLING  55
  34.  
  35. #define SPARKING 120
  36.  
  37. void Fire2012()
  38. {
  39. // Array of temperature readings at each simulation cell
  40.   static byte heat[NUM_LEDS];
  41.  
  42.   // Step 1.  Cool down every cell a little
  43.     for( int i = 0; i < NUM_LEDS; i++) {
  44.       heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
  45.     }
  46.  
  47.     // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  48.     for( int k= NUM_LEDS - 1; k >= 2; k--) {
  49.       heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  50.     }
  51.    
  52.     // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  53.     if( random8() < SPARKING ) {
  54.       int y = random8(7);
  55.       heat[y] = qadd8( heat[y], random8(160,255) );
  56.     }
  57.  
  58.     // Step 4.  Map from heat cells to LED colors
  59.     for( int j = 0; j < NUM_LEDS; j++) {
  60.       CRGB color = HeatColor( heat[j]);
  61.       int pixelnumber=j;
  62.          Serial.print("Pix ");
  63.          Serial.println(pixelnumber);
  64.         leds[pixelnumber] = color;
  65.         pixelnumber = (NUM_LEDS_X2-1) - j;
  66.          Serial.print("Pix ");
  67.          Serial.println(pixelnumber);
  68.         leds[pixelnumber] = color;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment