This isn't purely FastLED related but I thought I would share since it may

This isn’t purely FastLED related but I thought I would share since it may affect users who use the arduino map() function (particularly with potentiometers). I was banging my head a few weeks back because I noticed that whenever I selected the final mapped value on my potentiometer, I would get a weird “bounce” issue which manifests itself as flickering between that value and the previous value. I initially thought it was due to the potentiometer itself but swapping in new ones didn’t fix the problem.

So I traced it a bit further and it seems the map() function itself has an issue and is covered here https://github.com/arduino/Arduino/issues/2466.

If you plan on using map(), try this one which was suggested on the Github issue discussion:

long fixed_map(long x, long in_min, long in_max, long out_min, long out_max) {
if ((in_max - in_min) > (out_max - out_min)) {
return (x - in_min) * (out_max - out_min+1) / (in_max - in_min+1) + out_min;
}
else
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
}

As taken from the page:

“To give a real world scenario as to why this needs changed consider this. You are using the arduino with a sensor to sample data and based on this data set a servo into 1 of 4 positions. The arduino uses a 10 bit adc and outputs integers from 0 to 1023. You would use map(x, 0, 1023, 1, 4). With the map function as it is currently the only time position 4 would be active is when the arduino outputs the integer 1023. With my proposed change each position would get an equal share of the possible range. When they converted this function from a float function to an integer function they didn’t consider that the output is no longer a value but a position. Value mapping maps one value to another and the function works perfectly for floats. Positional mapping distributes the input as evenly as possible to the output and the function as is doesn’t do that.”

My project specifically uses positional mapping which is when the problem comes up.

Thank you for sharing this.