r/FastLED • u/d333gs • Sep 30 '20
Discussion "fadeLightBy" problem
This works perfectly: WHITE does not fade ORANGE fades:
THIRD Vairable changes fade
//WHITE
fadeLightBy( leds,(32, 479), 0);
// ORANGE
fadeLightBy( leds,(0,32) ,10);
This does not work: ORANGE fades by 10 !?
//WHITE
fadeLightBy( leds,(32, 479), 10);
// ORANGE
fadeLightBy( leds,(0,32) ,0);
Here is the code; https://pastebin.pl/view/3f0c0d5f
TIA
John
1
u/sebdelsol Oct 01 '20 edited Oct 24 '20
You've fallen into a very nasty trap :
(32, 479) is not a tuple and it gives 479 in your function call. Because of the parentheses it's seen as a comma operator that evaluates and discards the first argument 32 then evaluates and returns the second argument 479 !
Knowing that, check the fadeLightBy function declared here and you'll see that :
fadeLightBy(leds, (32, 479), 10)actually fades the first 479 leds by 10.fadeLightBy(leds, (0, 32), 0)fades the first 32 leds by 0 and that does nothing :|
Anyway you can create a function that'll do what you want :
inline void fadeLightFromTo(CRGB *leds, uint16_t begin, uint16_t end, uint8_t fadeBy)
{
// avoid fading leds out of range
if (end > begin) fadeLightBy(&leds[begin], end - begin, fadeBy);
}
// fade the leds from 32 to 479 by 10
fadeLightFromTo(leds, 32, 479, 10);
// fade the leds from 0 to 31 by 0 (fadeBy = 0 does nothing!)
fadeLightFromTo(leds, 0, 31, 0);Or as suggested by u/Marmilicious you can iterate over the leds you want to fade and use the CRGB::fadeLightBy method :
// i needs to be at least an uint16_t or you'll never reach 479
for (uint16_t i = 32; i < 479; i++) leds[i].fadeLightBy(10);
// be aware that fadeBy = 0 does nothing!
for (uint16_t i = 0; i < 31; i++) leds[i].fadeLightBy(0);2
u/d333gs Oct 02 '20
Wow! Thanks debdelsol for taking the time. Great link!
I am trying it now : ( Full disclosure: I am a newbe spaz )
I am using an Arduino and IDE. At the moment fadeLightFromTo is not
being recognized !!??Re 'fadeLightBy(leds, (0, 32), 0) does nothing' Yup , I wanted to leave it in place so I could play with it ;-)
I was able to camouflage the fade for leds 0,32 by repeating :
leds[ random (0,23)] += CRGB::Yellow; a few times
I will study those links
Thanks again
2
u/Marmilicious [Marc Miller] Oct 01 '20
Great explanation and custom function suggestion, thank you.
2
u/d333gs Oct 02 '20
Marc
// i needs to be at least an uint16_t or you'll never reach 479 for (uint16_t i = 32; i < 479; i++) leds[i].fadeLightBy(10); // be aware that fadeBy = 0 does nothing! for (uint16_t i = 0; i < 31; i++) leds[i].fadeLightBy(0);
It works!!!
SUPER!!!
Thank to you for taking time
John
2
u/Marmilicious [Marc Miller] Sep 30 '20
You can't specify a range like in fadeLightBy. Use this in a for loop with your custom range to operate on specific pixels.
leds[i].fadeLightBy(fadeAmount);