shdowmyst

Fire effect by danesparza

Jul 22nd, 2016
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #define PIN 6
  3.  
  4. Adafruit_NeoPixel strip = Adafruit_NeoPixel(29, PIN, NEO_GRB + NEO_KHZ800);
  5.  
  6.  
  7. void setup() {
  8.   strip.begin();
  9.   strip.setBrightness(brightness);
  10.   strip.show(); // Initialize all pixels to 'off'
  11. }
  12.  
  13. void loop() {
  14.  
  15.   //  Uncomment one of these RGB (Red, Green, Blue) values to
  16.   //  set the base color of the flame.  The color will flickr
  17.   //  based on the initial base color
  18.  
  19.   //  Regular (orange) flame:
  20.   //  int r = 226, g = 121, b = 35;
  21.  
  22.   //  Purple flame:
  23.   //  int r = 158, g = 8, b = 148;
  24.  
  25.   //  Green flame:
  26.   int r = 74, g = 150, b = 12;
  27.  
  28.   //  Flicker, based on our initial RGB values
  29.   for(int i=0; i<strip.numPixels(); i++) {
  30.     int flicker = random(0,55);
  31.     int r1 = r-flicker;
  32.     int g1 = g-flicker;
  33.     int b1 = b-flicker;
  34.     if(g1<0) g1=0;
  35.     if(r1<0) r1=0;
  36.     if(b1<0) b1=0;
  37.     strip.setPixelColor(i,r1,g1, b1);
  38.   }
  39.   strip.show();
  40.  
  41.   //  Adjust the delay here, if you'd like.  Right now, it randomizes the
  42.   //  color switch delay to give a sense of realism
  43.   delay(random(10,113));
  44. }
Advertisement
Add Comment
Please, Sign In to add comment