Say you were mapping a reading of 128 from the 20-1023 range into the 10-255 range, just to have 5 different #s to show.
Then the output would be:
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (128 - 20) * (255 - 10) / (1023 - 10) + 10;
}
Or (108 * 245)/1013 + 10 = 36
This case:
val = map(val, 0, 1023, 0, 255);
is really just output = input/4
look at in binary: 11111111xx ->11111111
10 bits to 8 bits is right shift 2, the xx bits get dropped off. Each right shift by 1 is same as divide by 2, 2 shifts = divide by 4.