// Saw a LED pattern I liked and tried to replicate it in code
// note for anything specific yet, mainly trying to see if I can code it like in the video
// https://youtu.be/iOL7UZpYnXY?t=204
// Still having issues with the "wrap around" of the effect on the ring version
#include <FastLED.h>
#define NUM_LEDS 80
CRGBArray<NUM_LEDS> leds;
//Using two arrays to view what it looks like as a strip as well as in a ring
CRGBSet stripled (leds (0, NUM_LEDS-1));
CRGBSet ringled (leds (0, NUM_LEDS-1));
float startpos = 30.0;
float increment = 0.0;
float maxvalue = 6.0;
float ipos = startpos;
float invpos = startpos;
CRGB splashcolor = CRGB(255, 50, 50);
double velocity = 0.2; //How fast to increment the splash around the ring
float fadeby = 6.0;
bool displayon = true;
void setup() {
FastLED.addLeds<SK6812, 10, GRB>(leds, NUM_LEDS);
FastLED.addLeds<SK6812, 9, GRB>(leds, NUM_LEDS);
Serial.begin(115200);
}
void loop() {
//Generate a new "splash" every 1 second
EVERY_N_MILLISECONDS(200)
{
startpos = random(1,NUM_LEDS-1);
ipos = startpos;
invpos = startpos;
increment = 0.0;
maxvalue = 6.0;
if (maxvalue > NUM_LEDS)
maxvalue -= NUM_LEDS;
displayon = true;
}
// Only draw pixels while there is a splash to animate
if(displayon)
showsplash();
//Fade everything by a little so the splash of color shows with a delay
stripled.fadeToBlackBy(fadeby);
FastLED.show();
}
void showsplash()
{
//Increment the LED being lit
ipos += velocity;
invpos -= velocity;
increment += velocity;
//Wrap around the ring / strip
if(invpos < 0)
invpos = NUM_LEDS + invpos;
if(ipos >= NUM_LEDS)
ipos = ipos - NUM_LEDS;
//Only splash for 8 or so pixels (set by maxvalue)
if (increment > maxvalue)
displayon = false;
stripled[ipos] = splashcolor;
stripled[invpos] = splashcolor;
}