You need to translate one range of values to another. I am writing on Python. In Arduino scripts, there is such a function as Map, it is interesting if there is something like that on Python. Below Description of the MAP function from Arduino
map (Value, FromLow, Fromhigh, Tolow, Tohigh)
The function proportionally tolerates the value (value
) from the current range of values (fromLow .. FromHigh
) in a new range (Tolow .. Tohigh
) set by parameters.
Answer 1, Authority 100%
This is the source code of this function from Documentation
Long Map (Long X, Long In_min, Long In_max, Long Out_min, Long Out_max)
{
RETURN (X - IN_MIN) * (OUT_MAX - OUT_MIN) / (IN_MAX - IN_MIN) + OUT_MIN;
}
on python, apparently, will be somehow so (the code did not check)
Def Arduino_map (x, in_min, in_max, out_min, out_max):
RETURN (X - IN_MIN) * (OUT_MAX - OUT_MIN) / (IN_MAX - IN_MIN) + OUT_MIN