Hi all! Very slowly starting to learn about the delights of FastLED,

Hi all!
Very slowly starting to learn about the delights of FastLED, but there’s one issue i’m really stuck on:

How do you fade/transition between random colors?
I’m setting a random color on a button press with
int sensorValue = random8();

and then applying it to my Neopixel wheel with:

fill_solid(leds, NUM_LEDS, CHSV(sensorValue,255,i));

Which works well, every time i press the button the wheel changes to a random color. But i’d really like it to transition to that color over a set period (1s for e.g.) I’m looking through the docs but i can’t find anything.

If anybody could point me in the right direction then that would be great. All of the examples I find always seem to just go 255, 0, 0 to 0, 255, 0 which I can don, but can’t apply it to other colors.

You need to create a loop that gradually goes from ‘oldSensorValue’ to ‘newSensorValue’

something like…

for (int x = oldSensorValue; x<newSensorValue; x++){
fill_solid(leds, NUM_LEDS, CHSV(x,255,i));
show.leds();
delay(some delay);
}

you may want to start be checking if it is preferable to count up or down to the newSensorValue. For example if oldSensorValue = 10 and newSensorValue = 245 you would want to count down with 20 steps as it is the shortest path instead of counting up which would take 235 steps.

Some documentation is at:

http://fastled.io/docs/3.1/group___colorutils.html

Try this:

// Blend
leds[i] = blend(CRGB::Red, CRGB::Blue, sin8(mysine));

If you want to do a gradient between a couple of points, try these examples:

fill_gradient_RGB(leds, startpos, 0x000011, endpos, 0x110000);
fill_gradient_RGB(leds, NUM_LEDS, CRGB(50,0,200), CRGB(80,200,240)); // up to 4 of these

//FORWARD_HUES, BACKWARD_HUES, SHORTEST_HUES, LONGEST_HUES
fill_gradient(leds, startpos, CHSV(50, 255,255) , endpos, CHSV(150,255,255), SHORTEST_HUES);
fill_gradient(leds, NUM_LEDS, CHSV(50, 255,255), CHSV(100,255,255), LONGEST_HUES); // up to 4 of these

Finally, here’s an example:

@JP_Roy Thanks for this. I’ll have a look in to that. I can already picture the function in my head so i’ll do some tinkering shortly. I’m just wondering how i’d be able to say 'go to this color, over the period of 1s. Because obviously the count from say 10 to 20 is a lot quicker than the count from 10 to 255… But I think both would be super quick anyway based on how quick the loop() function runs.

@Andrew_Tuline thanks for these. I’ll let you know how I get on

if you want any and all transitions to be smooth and always have the same duration. you may want to add something like…

int diff = oldSensorValue - newSensorValue;

or alternately…

int diff = newSensorValue - oldSensorValue;

then set…

someDelay = 1000 / diff;

now if you execute a loop like I suggested, you will always have a transition that takes close to a second to execute.

Note that if the diff is very small, you may not even notice the change so you may actually prefer to take the long way around to always see some transition.