Guest User

Untitled

a guest
Dec 5th, 2023
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.50 KB | Source Code | 0 0
  1. // Libraries
  2. #include "FastLED.h"
  3.  
  4. #define NUM_LEDS 60
  5. CRGB leds[NUM_LEDS];
  6. #define PIN 3
  7. #define BRIGHTNESS  50
  8.  
  9. void setup()
  10. {
  11.  delay(1000); // 1 second delay for recovery
  12.  
  13.   FastLED.addLeds<WS2813, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 ); // tell FastLED about the LED strip configuration
  14.   FastLED.setBrightness(BRIGHTNESS); // set master brightness control
  15. }
  16.  
  17. void loop() {
  18.   meteorRain(255,255,255,10, 64, true, 10);
  19. }
  20.  
  21. void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  22.   setAll(0,0,0);
  23.  
  24.   for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
  25.    
  26.    
  27.     // fade brightness all LEDs one step
  28.     for(int j=0; j<NUM_LEDS; j++) {
  29.       if( (!meteorRandomDecay) || (random(10)>5) ) {
  30.         fadeToBlack(j, meteorTrailDecay );        
  31.       }
  32.     }
  33.    
  34.     // draw meteor
  35.     for(int j = 0; j < meteorSize; j++) {
  36.       if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
  37.         setPixel(i-j, red, green, blue);
  38.       }
  39.     }
  40.    
  41.     showStrip();
  42.     delay(SpeedDelay);
  43.   }
  44. }
  45.  
  46. void fadeToBlack(int ledNo, byte fadeValue) {
  47.    leds[ledNo].fadeToBlackBy( fadeValue );
  48. }
  49.  
  50. void showStrip() {
  51.    FastLED.show();
  52. }
  53.  
  54. void setPixel(int Pixel, byte red, byte green, byte blue) {
  55.    leds[Pixel].r = red;
  56.    leds[Pixel].g = green;
  57.    leds[Pixel].b = blue;
  58. }
  59.  
  60. void setAll(byte red, byte green, byte blue) {
  61.   for(int i = 0; i < NUM_LEDS; i++ ) {
  62.     setPixel(i, red, green, blue);
  63.   }
  64.   showStrip();
  65. }
Advertisement
Add Comment
Please, Sign In to add comment