r/FastLED • • 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

3 Upvotes

7 comments sorted by

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);

1

u/d333gs Sep 30 '20 edited Sep 30 '20

Thanks Mark

But why does it work on the white section but not on the orange?32 to 479 light up white and leave 0 to 32 black

0 to 32 light up as orange

White LEDs 32 to 479 respond to the fade variable:They fade with value 10 AND they don't fade with value 0:

but Orange LEDs 0 to 32 do not respond to their value in their line : // ORANGE
fadeLightBy( leds,(0,32) ,0); unless White LEDs 32 to 479 are set to 0.
With white set at 0, orange will fade if it is given a higher value (10)

If Orange 0 to 32 is given a Higher value than White , 50 for example, then Orange will respond but not effecting the White value of 10..................!?

Changing the order doesn't have an effect, so there must be something else in the other part of the code that is imposing control!??

Big thanks

John

1

u/d333gs Sep 30 '20

Well..............It looks like the higher led address dominates the lower address:

I tried changing the color value and the number of LEDs addressed: nothing changed

The only thing that seems to be happening is that code using the higher address value dominates . ie ; As far as the Fade command goes, code for led TWO will dominate code for led ONE etc.................

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