ldirko

fire2x2

Sep 22nd, 2020
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Perlin noise fire procedure
  2. //16x16 rgb led matrix demo
  3. //Yaroslaw Turbin, 22.06.2020
  4. //https://vk.com/ldirko
  5. //https://www.reddit.com/user/ldirko/
  6. //https://www.reddit.com/r/FastLED/comments/hgu16i/my_fire_effect_implementation_based_on_perlin/
  7.  
  8. //idea in make perlin noise with time offset X and Z coord
  9. //this automatic scroll fire pattern    
  10. //and distort fire noise.
  11. //then substract Y based coodrd value to shift
  12. //fire color (not brightness) in palette.
  13. //this fadeout color from bottom matrix to up.
  14. //this need some palette tweak for good looking fire color
  15.  
  16.  
  17. #include "FastLED.h"
  18.  
  19. // Matrix size
  20. #define NUM_ROWS 2
  21. #define NUM_COLS 2
  22. #define NUM_LEDS NUM_ROWS * NUM_COLS
  23.  
  24. // LEDs pin
  25. #define DATA_PIN 3
  26.  
  27. // LED brightness
  28. #define BRIGHTNESS 255
  29.  
  30.  
  31. // Define the array of leds
  32. CRGB leds[NUM_LEDS];
  33.  
  34. DEFINE_GRADIENT_PALETTE( firepal ) {    // define fire palette
  35.    0,     0,  0,  0,   //black
  36.   32,   255,  0,  0,  // red
  37.   190, 255, 255, 0, //yellow
  38.   255,   255, 255, 255  // white
  39. };
  40.  
  41. CRGBPalette16 myPal = firepal;
  42.  
  43.  
  44. void setup() {
  45.   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  46.   FastLED.setBrightness(BRIGHTNESS);
  47. }
  48.  
  49.  
  50. void loop() {
  51.  
  52. EVERY_N_MILLISECONDS(20) {fire(); }
  53. FastLED.show();
  54. }
  55.  
  56. void fire (){
  57. static int  a = 0;
  58.  
  59.   for (int i = 0; i < NUM_COLS; i++) {
  60.     for (int j = 0; j < NUM_ROWS; j++) {
  61.       leds[XY(i,j)] = ColorFromPalette (myPal, inoise8 (i * 80 , j * 80+ a , a /3), BRIGHTNESS);   
  62. }
  63. }
  64. a+=20;
  65. }
  66.  
  67. uint8_t XY (uint8_t x, uint8_t y) { return (y * NUM_COLS + x);}     //simple function to find led number in led matrix,
  68.                                                                     //change this to your routine
  69.                                                                     //or generate XY function for your matrix there:
  70.                                                                     //https://macetech.github.io/FastLED-XY-Map-Generator/
Add Comment
Please, Sign In to add comment