Kennetht

Fire matrix

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