KVEL

RAMMSTEIN_Mini

May 8th, 2022
1,552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN     2
  4. #define COLOR_ORDER GRB
  5. #define CHIPSET     WS2811
  6. #define NUM_LEDS    16
  7.  
  8. #define BRIGHTNESS  200
  9. #define FRAMES_PER_SECOND 60
  10.  
  11. bool gReverseDirection = false;
  12.  
  13. CRGB leds[NUM_LEDS];
  14. CRGBPalette16 gPal;
  15.  
  16. void setup() {
  17.   delay(3000); // sanity delay
  18.   FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  19.   FastLED.setBrightness( BRIGHTNESS );
  20. }
  21.  
  22. void loop()
  23. {
  24.   // Add entropy to random number generator; we use a lot of it.
  25.   random16_add_entropy( random());
  26.   Fire2012WithPalette(); // run simulation frame, using palette colors
  27.  
  28.   FastLED.show(); // display this frame
  29.   FastLED.delay(1000 / FRAMES_PER_SECOND);
  30. }
  31.  
  32. #define COOLING  55
  33.  
  34. // SPARKING: What chance (out of 255) is there that a new spark will be lit?
  35. // Higher chance = more roaring fire.  Lower chance = more flickery fire.
  36. // Default 120, suggested range 50-200.
  37. #define SPARKING 120
  38.  
  39.  
  40. void Fire2012WithPalette()
  41. {
  42. // Array of temperature readings at each simulation cell
  43.   static byte heat[NUM_LEDS];
  44.  
  45.   // Step 1.  Cool down every cell a little
  46.     for( int i = 0; i < NUM_LEDS; i++) {
  47.       heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
  48.     }
  49.  
  50.     // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  51.     for( int k= NUM_LEDS - 1; k >= 2; k--) {
  52.       heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  53.     }
  54.    
  55.     // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  56.     if( random8() < SPARKING ) {
  57.       int y = random8(7);
  58.       heat[y] = qadd8( heat[y], random8(160,255) );
  59.     }
  60.  
  61.     // Step 4.  Map from heat cells to LED colors
  62.     for( int j = 0; j < NUM_LEDS; j++) {
  63.       // Scale the heat value from 0-255 down to 0-240
  64.       // for best results with color palettes.
  65.       byte colorindex = scale8( heat[j], 240);
  66.       CRGB color = ColorFromPalette( gPal, colorindex);
  67.       int pixelnumber;
  68.       if( gReverseDirection ) {
  69.         pixelnumber = (NUM_LEDS-1) - j;
  70.       } else {
  71.         pixelnumber = j;
  72.       }
  73.       leds[pixelnumber] = color;
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment