Hello! I was wondering if someone could help me out a little with a

fastled-support
gplus
(Craig Sanford) #1

Hello! I was wondering if someone could help me out a little with a gradual fading function. I am essentially trying to create a slow “light saber” or “fill up” effect for a project I am doing. I’ve done a few different functions to achieve this and I feel like the pastebin i posted below is close. I tried a linear increase and it didn’t look right. So after much reading I attempted to create a more exponential increase which is just a little fast. I was sort of hoping for something along the lines of when the first LED (very bottom of the strip) is on max brightness the LED half way up or so would be just starting to light up. If I could multiply each step by anything smaller than 2 (like 1.5) even wrapping the outcome in a Round() function causes the lights to blink when they hit the max brightness. In the end I’m sure what I’m looking for is some kind of logarithmic or exponential function that’s just slower or on less of a curve but I’ve hit the end of my math know how.

Any help is appreciated!

Current code:
https://pastebin.com/D6X8eScX

(Andrew Tuline) #2

Gee, that code looks very familiar. . . and on pastebin too!

You might want to try using a float as your multiplier, as they can quite often mix with inteters.

Also, since there won’t be too many increments per LED, you could use a brightness lookup table and have a short equation to determine which entry to pick for each LED as you loop umpteen times. I’d keep a loop counter or use millis().

Finally, not sure if sine waves, easing or lerps might work, but hey, experimentation is half the fun.

(Craig Sanford) #3

@Andrew_Tuline Thanks. I had considered the lookup table as i had read through a few posts on them. I’m just not certain on how to loop through each LED and determine where its current value is on the table and increment it. But I think that’ll be my next attempt.

I tried using float values like 1.25f on the multiplication to increment the brightness but even when I wrap that up in a Round() it causes a weird issue where some LEDs that have gotten to max brightness dim. Really kind of odd…

I also considered lerp. But lerp by definition is linear which I have already done and it doesn’t really look right so I’m not sure that’s what I really want to try. Guess there is no hurt in giving it a shot though.

Have not tried sine yet but… well I suck at math and don’t really appreciate how it works.

(Craig Sanford) #4

Looks like an array of values did the trick! Here’s my final code if anyone is interested.
https://pastebin.com/hJgUg5u6

(Andrew Tuline) #5

Now that you’ve got your fade in, I might suggest a bit of shimmering once that’s complete. With the following example (code is in link), you could change the palette to various shades of green and bring it alive: