Hi, I'm experimenting with fadelightby and have a script which initially lights up different

Hi,

I’m experimenting with fadelightby and have a script which initially lights up different sections of my 150 led strip with blocks of color (and a rainbow thrown in just to be clever) then fades to black and back up to 255 again. The only method I know to fade and brighten is to use a for loop within the void loop:

for(int i = 0; i < NUM_LEDS; i++ ) {
leds[i].fadeLightBy(brightness);
}

Which works fine, but it seems a bit long-winded: it sets the brightness value of each led individually. Isn’t there a global fade or brightness command I can use to address the whole strip instead? I’m imagining something like:

leds.fadeLightBy(brightness);
leds[0,150].fadeLightBy(brightness);
leds[NUM_LEDS].fadeLightBy(brightness);
etc.

As a complete noob I used to light all my leds up using a similar for loop with e.g.
leds[i] = CRGB::Red
But now I’ve progressed a bit I use fill_solid to do it in one fell swoop. I’m speculating along similar lines for setting the brightness all at once instead of doing it 150 times (even though it does seem very fast). Can it be done?

Thanks :slight_smile:

fadeToBlackBy( leds, NUM_LEDS, 20); //fade by 7.8% (20/256th)

fadeLightBy( leds, NUM_LEDS, 128); // fade by 50%

Thanks Marc, works good!
What’s the difference between the two, do you know? According to the github site both are “a synonym for nscale8”.

Repeatedly using fadeToBlack will eventually go all the way to zero. FadeLight won’t ever go all the way to zero.