void loop() {
for(int i = 0; i < NUM_LEDS; i+5)
{
leds[i] = CRGB::Red;
FastLED.show();
delay(1000);
}
}
Is there a way to get every 5th LED turned on at once? I’ve been playing with it for a couple of hours but can’t seem to math up anything that makes sense.
Did you mean “i += 5” instead of “i+5” in the for loop? The expression “i+5” will only take the value of i and then add 5 but not do anything with the result.
Calling FastLED.show(); will update your pixels with whatever changes have been made since the last time show() was called. You can update a single pixel and then call show() to see the change for that single pixel, or update 100 pixels and then call show() and have them all update simultaneously.
You can pull the show() out of the loop like below and then all changed pixels will update together.
void loop() {
for(int i = 0; i < NUM_LEDS; i+=5) {
leds[i] = CHSV(random8(), 255, 255); // choose random color
}
FastLED.show();
delay(1000);
}
You can update the value for a pixel a dozen times, but you won’t see those changes if you don’t call show() after each change. This can sometimes be used to your advantage. For example, the below first fills the entire strip with a random color, and then every fifth pixel with another color. By waiting to call show() until the end we only see the final result and not the intermediate step of filling the entire strip a single color.
void loop() {
// fill entire strip will random color
fill_solid(leds, NUM_LEDS, CHSV(random8(),255,255) );
uint8_t myColor = random8(); //pick a random color
for(int i = 0; i < NUM_LEDS; i+=5) {
leds[i] = CHSV(myColor, 255, 255);
}
FastLED.show();
delay(1000);