Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Libraries
- #include "FastLED.h"
- #define NUM_LEDS 60
- CRGB leds[NUM_LEDS];
- #define PIN 3
- #define BRIGHTNESS 50
- void setup()
- {
- delay(1000); // 1 second delay for recovery
- FastLED.addLeds<WS2813, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 ); // tell FastLED about the LED strip configuration
- FastLED.setBrightness(BRIGHTNESS); // set master brightness control
- }
- void loop() {
- meteorRain(255,255,255,10, 64, true, 10);
- }
- void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
- setAll(0,0,0);
- for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
- // fade brightness all LEDs one step
- for(int j=0; j<NUM_LEDS; j++) {
- if( (!meteorRandomDecay) || (random(10)>5) ) {
- fadeToBlack(j, meteorTrailDecay );
- }
- }
- // draw meteor
- for(int j = 0; j < meteorSize; j++) {
- if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
- setPixel(i-j, red, green, blue);
- }
- }
- showStrip();
- delay(SpeedDelay);
- }
- }
- void fadeToBlack(int ledNo, byte fadeValue) {
- leds[ledNo].fadeToBlackBy( fadeValue );
- }
- void showStrip() {
- FastLED.show();
- }
- void setPixel(int Pixel, byte red, byte green, byte blue) {
- leds[Pixel].r = red;
- leds[Pixel].g = green;
- leds[Pixel].b = blue;
- }
- void setAll(byte red, byte green, byte blue) {
- for(int i = 0; i < NUM_LEDS; i++ ) {
- setPixel(i, red, green, blue);
- }
- showStrip();
- }
Advertisement
Add Comment
Please, Sign In to add comment