# Just looking for clarification on FadeToBlackBy.

(allanGEE) #1

Just looking for clarification on FadeToBlackBy.

If I light up an LED and do a FadeToBlackBy (say 25%), the code would need to call the FadeToBlackBy four times during the loop, before the LED would be ‘off’, correct? In other words, you can’t tell an LED to fade to black and then just leave it alone.

I’m creating some horizontal lines moving up a grid, and it looks a little smoother if a fully lit line is “trailed” by a dimly lit line, and then a black line. Currently, I’m just changing the V in CHSV.

On a serpentine grid 6 LEDS wide…
LEDS 00-05 get lit up fully.
Then
LEDS 06-11 get lit up fully, LEDS 00-05 V=100 or so.
Then
LEDS 12-17 get lit up fully, LEDS 06-11 V=100, LEDS 00-05 off
Etc…

It’ll work, but doesn’t feel as ‘elegant’ as some of the code I’ve seen here. I’m basically building still frames that are displayed on the grid similar to a movie.

I’m currently playing with the confetti code to mess around with FadeToBlackBy. It’s a lot of fun experimenting, but sometimes I feel like I’m trying to carve a turkey with a chainsaw.

(Daniel Garcia) #2

Your understanding of the math is a little bit off. FadeToBlackBy 25% reduces the value by 25% of it’s current value. Not by it’s initial value. So if you have 255,255,255 after the first fadeToBlackBy(64); it will be 191,191,191. After the second fadeToBlackBy it will be 143,143,143, etc… it will actually take 16 calls to fadeToBlackBy(64) to drive 255,255,255 down to black.

And yes, you need to call fadeToBlackBy on each led that you want to fade for each frame before you call FastLED.show()

(allanGEE) #3

@Daniel_Garcia Thank you!