Mapping 0v to 5v range to -5v to 5v range with programming. Is it possible?

Hello all,

I was trying to do it in my code but no luck with few methods I tried. So, I am asking here is there any way to map 0 to 5 range number to new range like -5 to 5?

map function by Arduino and custom made map_float function just fails because of denominator becomes zero when we input data in formula:

float mapfloat(long x, long in_min, long in_max, long out_min, long out_max)
{
 return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
}

Any help will be very much appreciated.

Thank you.

What values are you calling that function with? The denominator will be zero only when in_min equals in_max.

To map (0 to 5) to (-5 to 5), multiply by 2, and subtract 5.

aarg: To map (0 to 5) to (-5 to 5), multiply by 2, and subtract 5.

Yeah, no reason to be fancy.