#include "FastLED.h"
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
#define PIN 6
void setup()
{
FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop()
{
meteorRain(CRGB(0x00,0x00,0x00), CRGB(0xff,0xff,0xff),10 ,120 ,true, 40);
}
void meteorRain(CRGB ColorBackground, CRGB ColorMeteor, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
{
// set background color
fill_solid( leds, NUM_LEDS, ColorBackground );
for(int i = 0; i < NUM_LEDS; i++)
{
// fade color to background color for all LEDs
for(int j=0; j < NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10) > 5) ) {
leds[j] = fadeTowardColor(leds[j], ColorBackground, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j < NUM_LEDS) && (i-j >= 0) ) {
leds[i-j]= ColorMeteor;
}
}
FastLED.show();
delay(SpeedDelay);
}
}
// Functions from Kriegsman example
CRGB fadeTowardColor( CRGB& cur, const CRGB& target, uint8_t amount)
{
nblendU8TowardU8( cur.red, target.red, amount);
nblendU8TowardU8( cur.green, target.green, amount);
nblendU8TowardU8( cur.blue, target.blue, amount);
return cur;
}
// function used by "fadeTowardColor"
void nblendU8TowardU8( uint8_t& cur, const uint8_t target, uint8_t amount)
{
if( cur == target) return;
if( cur < target ) {
uint8_t delta = target - cur;
delta = scale8_video( delta, amount);
cur += delta;
} else {
uint8_t delta = cur - target;
delta = scale8_video( delta, amount);
cur -= delta;
}
}