Advertisement
claudiusmarius

Meteor

Nov 15th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. //==================================
  2. //Version ATTiny
  3.   #include <Adafruit_NeoPixel.h>
  4.   #define PIN 0
  5.   #define NUM_LEDS 110
  6.  
  7.   Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
  8.  
  9.   void setup() {
  10.   strip.begin();
  11.   strip.show(); // Initialize all pixels to 'off'
  12.   }
  13.  
  14.   void loop() {
  15.   meteorRain(0xff,0xff,0xff,5, 60, false, 0);
  16.   }
  17.  
  18.   void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  19.   setAll(0,0,0);
  20.  
  21.   for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
  22.  
  23.   for(int j=0; j<NUM_LEDS; j++) {
  24.   if( (!meteorRandomDecay) || (random(10)>5) ) {
  25.   fadeToBlack(j, meteorTrailDecay );        
  26.   }
  27.   }
  28.  
  29.   for(int j = 0; j < meteorSize; j++) {
  30.   if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
  31.   setPixel(i-j, red, green, blue);
  32.   }
  33.   }
  34.    
  35.   showStrip();
  36.   delay(SpeedDelay);
  37.   }
  38.   }
  39.  
  40.   void fadeToBlack(int ledNo, byte fadeValue) {
  41.   #ifdef ADAFRUIT_NEOPIXEL_H
  42.   uint32_t oldColor;
  43.   uint8_t r, g, b;
  44.   int value;
  45.    
  46.   oldColor = strip.getPixelColor(ledNo);
  47.   r = (oldColor & 0x00ff0000UL) >> 16;
  48.   g = (oldColor & 0x0000ff00UL) >> 8;
  49.   b = (oldColor & 0x000000ffUL);
  50.  
  51.   r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
  52.   g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
  53.   b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
  54.    
  55.   strip.setPixelColor(ledNo, r,g,b);
  56.   #endif
  57.   #ifndef ADAFRUIT_NEOPIXEL_H
  58.   #endif  
  59.   }
  60.   //===================================
  61.   void showStrip() {
  62.   #ifdef ADAFRUIT_NEOPIXEL_H
  63.   strip.show();
  64.   #endif
  65.   #ifndef ADAFRUIT_NEOPIXEL_H
  66.   #endif
  67.   }
  68.  
  69.   void setPixel(int Pixel, byte red, byte green, byte blue) {
  70.   #ifdef ADAFRUIT_NEOPIXEL_H
  71.   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  72.   #endif
  73.   #ifndef ADAFRUIT_NEOPIXEL_H
  74.   #endif
  75.   }
  76.  
  77.   void setAll(byte red, byte green, byte blue) {
  78.   for(int i = 0; i < NUM_LEDS; i++ ) {
  79.   setPixel(i, red, green, blue);
  80.   }
  81.   showStrip();
  82.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement