It's probably been done before, but I couldn't find exactly what I wanted,

Christopher_Kirkman1
Sun, 03 Dec 2017 07:11:40 +0000
FastLED Archive

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();
}

3 posts - 1 participant