Code: Select all
void colorChase(uint32_t c, uint8_t wait) {
int i;
int incr = 3; // how many LEDs to skip while chasing
int width = 10; //a segment of these many LEDs will move up and down the strip.
int j;
// Start by turning all pixels off:
for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);
// Then display 'width' pixels at a time
for(i=0; i<strip.numPixels(); i=i+incr) {
for(j=i; j<i+width; j++) {
strip.setPixelColor(j, c); // Set new pixels 'on'
}
strip.show(); // Refresh LED states
for(j=i; j<i+width; j++) {
strip.setPixelColor(j, 0); // Erase pixels, but don't refresh!
}
delay(wait); // this delay is not the only delay in the loop. I think the strip.shot() command also adds a substantial additional delay
}
for(i=strip.numPixels(); i>0; i=i-incr) { //chasing backwards
for(j=i; j>i-width; j--) {
strip.setPixelColor(j, c); // Set new pixels 'on'
}
strip.show(); // Refresh LED states
for(j=i; j>i-width; j--) {
strip.setPixelColor(j, 0); // Erase pixels, but don't refresh!
}
delay(wait);
}
strip.show(); // Refresh to turn off last pixel
}