#include "FastLED.h"
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
#define PIN1 2
//#define PIN2 3
void setup()
{
//FastLED.addLeds<WS2811, PIN1, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2811, PIN2, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop()
{
meteorRain1(CRGB(0x80,0x00,0x00), CRGB(0x00,0x80,0x00),35 ,70 ,true, 10);
delay(100);
// meteorRain2(CRGB(0xFF,0x00,0x00), CRGB(0x00,0x80,0x00),35 ,70 ,true, 20);
// delay(5000);
}
void meteorRain1(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+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);
}
for(int i = NUM_LEDS+NUM_LEDS; i >=0; 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;
}
}
I sure hope I inserted the code the proper way. If not, I deeply apologize.
I have that wonderful Meteor Rain running and I have added a return trip so it goes out and back.
The meteor goes out and allows the background color(red) to fully fill in before the green meteor starts its return trip.
But when it gets back the red(background) doesn't fully fill in. I have played with various delays but can't quite get it cleaned up.
Much of the programming is a step above my knowledge so any help would be great.