abooseca

Untitled

Nov 26th, 2023
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN_1     9
  4. #define LED_PIN_2     12
  5. #define LED_PIN_3     6
  6. #define COLOR_ORDER GRB
  7. #define CHIPSET     WS2812
  8. #define NUM_LEDS_1    20
  9. #define NUM_LEDS_2    19
  10. #define NUM_LEDS_3    20
  11.  
  12. #define BRIGHTNESS  200
  13. #define FRAMES_PER_SECOND 20
  14.  
  15. bool gReverseDirection = false;
  16.  
  17. CRGB leds1[NUM_LEDS_1];
  18. CRGB leds2[NUM_LEDS_2];
  19. CRGB leds3[NUM_LEDS_3];
  20.  
  21. static byte heat1[NUM_LEDS_1];    // separate heat arrays for all 3 strips
  22. static byte heat2[NUM_LEDS_2];
  23. static byte heat3[NUM_LEDS_3];
  24.  
  25. void setup() {
  26.   delay(2000); // sanity delay
  27.   FastLED.addLeds<CHIPSET, LED_PIN_1, COLOR_ORDER>(leds1, NUM_LEDS_1).setCorrection( TypicalLEDStrip );
  28.   FastLED.addLeds<CHIPSET, LED_PIN_2, COLOR_ORDER>(leds2, NUM_LEDS_2).setCorrection( TypicalLEDStrip );
  29.   FastLED.addLeds<CHIPSET, LED_PIN_3, COLOR_ORDER>(leds3, NUM_LEDS_3).setCorrection( TypicalLEDStrip );
  30.   FastLED.setBrightness( BRIGHTNESS );
  31. }
  32.  
  33. void loop()
  34. {
  35.   // Add entropy to random number generator; we use a lot of it.
  36.   // random16_add_entropy( random());
  37.  
  38.   Fire2012_1(); // run simulation frame
  39.   Fire2012_2();
  40.   Fire2012_3();
  41.  
  42.   FastLED.show(); // display this frame
  43.   FastLED.delay(1000 / FRAMES_PER_SECOND);
  44. }
  45.  
  46.  
  47. // Fire2012 by Mark Kriegsman, July 2012
  48. // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY
  49. ////
  50. // This basic one-dimensional 'fire' simulation works roughly as follows:
  51. // There's a underlying array of 'heat' cells, that model the temperature
  52. // at each point along the line.  Every cycle through the simulation,
  53. // four steps are performed:
  54. //  1) All cells cool down a little bit, losing heat to the air
  55. //  2) The heat from each cell drifts 'up' and diffuses a little
  56. //  3) Sometimes randomly new 'sparks' of heat are added at the bottom
  57. //  4) The heat from each cell is rendered as a color into the leds array
  58. //     The heat-to-color mapping uses a black-body radiation approximation.
  59. //
  60. // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot).
  61. //
  62. // This simulation scales it self a bit depending on NUM_LEDS; it should look
  63. // "OK" on anywhere from 20 to 100 LEDs without too much tweaking.
  64. //
  65. // I recommend running this simulation at anywhere from 30-100 frames per second,
  66. // meaning an interframe delay of about 10-35 milliseconds.
  67. //
  68. // Looks best on a high-density LED setup (60+ pixels/meter).
  69. //
  70. //
  71. // There are two main parameters you can play with to control the look and
  72. // feel of your fire: COOLING (used in step 1 above), and SPARKING (used
  73. // in step 3 above).
  74. //
  75. // COOLING: How much does the air cool as it rises?
  76. // Less cooling = taller flames.  More cooling = shorter flames.
  77. // Default 50, suggested range 20-100
  78. #define COOLING  45
  79.  
  80. // SPARKING: What chance (out of 255) is there that a new spark will be lit?
  81. // Higher chance = more roaring fire.  Lower chance = more flickery fire.
  82. // Default 120, suggested range 50-200.
  83. #define SPARKING 100
  84.  
  85.  
  86. void Fire2012_1()
  87. {
  88. // Array of temperature readings at each simulation cell
  89.   static byte heat1[NUM_LEDS_1];
  90.  
  91.   // Step 1.  Cool down every cell a little
  92.     for( int i = 0; i < NUM_LEDS_1; i++) {
  93.       heat1[i] = qsub8( heat1[i],  random8(0, ((COOLING * 10) / NUM_LEDS_1) + 2));
  94.     }
  95.  
  96.     // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  97.     for( int k= NUM_LEDS_1 - 1; k >= 2; k--) {
  98.       heat1[k] = (heat1[k - 1] + heat1[k - 2] + heat1[k - 2] ) / 3;
  99.     }
  100.    
  101.     // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  102.     if( random8() < SPARKING ) {
  103.       int y = random8(7);
  104.       heat1[y] = qadd8( heat1[y], random8(160,255) );
  105.     }
  106.  
  107.     // Step 4.  Map from heat cells to LED colors
  108.     for( int j = 0; j < NUM_LEDS_1; j++) {
  109.       CRGB color = HeatColor( heat1[j]);
  110.       int pixelnumber;
  111.       if( gReverseDirection ) {
  112.         pixelnumber = (NUM_LEDS_1-1) - j;
  113.       } else {
  114.         pixelnumber = j;
  115.       }
  116.       leds1[pixelnumber] = color;
  117.     }
  118. }
  119. void Fire2012_2()
  120. {
  121. // Array of temperature readings at each simulation cell
  122.   static byte heat2[NUM_LEDS_2];
  123.  
  124.   // Step 1.  Cool down every cell a little
  125.     for( int i = 0; i < NUM_LEDS_2; i++) {
  126.       heat2[i] = qsub8( heat2[i],  random8(0, ((COOLING * 10) / NUM_LEDS_2) + 2));
  127.     }
  128.  
  129.     // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  130.     for( int k= NUM_LEDS_2 - 1; k >= 2; k--) {
  131.       heat2[k] = (heat2[k - 1] + heat2[k - 2] + heat2[k - 2] ) / 3;
  132.     }
  133.    
  134.     // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  135.     if( random8() < SPARKING ) {
  136.       int y = random8(7);
  137.       heat2[y] = qadd8( heat2[y], random8(160,255) );
  138.     }
  139.  
  140.     // Step 4.  Map from heat cells to LED colors
  141.     for( int j = 0; j < NUM_LEDS_2; j++) {
  142.       CRGB color = HeatColor( heat2[j]);
  143.       int pixelnumber;
  144.       if( gReverseDirection ) {
  145.         pixelnumber = (NUM_LEDS_2-1) - j;
  146.       } else {
  147.         pixelnumber = j;
  148.       }
  149.       leds2[pixelnumber] = color;
  150.     }
  151. }
  152. void Fire2012_3()
  153. {
  154. // Array of temperature readings at each simulation cell
  155.   static byte heat3[NUM_LEDS_3];
  156.  
  157.   // Step 1.  Cool down every cell a little
  158.     for( int i = 0; i < NUM_LEDS_3; i++) {
  159.       heat3[i] = qsub8( heat3[i],  random8(0, ((COOLING * 10) / NUM_LEDS_3) + 2));
  160.     }
  161.  
  162.     // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  163.     for( int k= NUM_LEDS_3 - 1; k >= 2; k--) {
  164.       heat3[k] = (heat3[k - 1] + heat3[k - 2] + heat3[k - 2] ) / 3;
  165.     }
  166.    
  167.     // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  168.     if( random8() < SPARKING ) {
  169.       int y = random8(7);
  170.       heat3[y] = qadd8( heat3[y], random8(160,255) );
  171.     }
  172.  
  173.     // Step 4.  Map from heat cells to LED colors
  174.     for( int j = 0; j < NUM_LEDS_3; j++) {
  175.       CRGB color = HeatColor( heat3[j]);
  176.       int pixelnumber;
  177.       if( gReverseDirection ) {
  178.         pixelnumber = (NUM_LEDS_3-1) - j;
  179.       } else {
  180.         pixelnumber = j;
  181.       }
  182.       leds3[pixelnumber] = color;
  183.     }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment