It’s probably been done before, but I couldn’t find exactly what I wanted, so when I figured it out on my own, I figured I’d share it. Here’s a way to do traveling stripes down the length of your LED strip without using a delay (the millis method). I’m using a Particle Photon board to drive the strip so declarations might vary slightly, but the math should be sound. If there’s a better way, I’m all ears.
int offset = 0;
void newCane(){
int numColors = 2;
int stripeLength = 10;
int travelSpeed = 75;
int color1 = CRGB::White;
int color2 = CRGB::Red;
if (currentMillis - previousMillis >= travelSpeed) {
previousMillis = currentMillis;
for(int i=0;i<NUM_LEDS;i++){
if( (i+offset)%(numColors*stripeLength)<stripeLength+1 ){
leds[i] = color2;
}else{
leds[i] = color1;
}
}
FastLED.show();
offset++;
if(offset>=NUM_LEDS) offset = 0;
}
}
void loop()
{
currentMillis = millis();
newCane();
}