PDA

View Full Version : [Question(s)] Maping a value in python

ROBOTMAN
01-29-2010, 10:54 PM
I was wondering if there was a way to map values in python. When programing the arduino there is a way to take a value and convert it into a smaller or larger value. This function for arduino is called map. After searching the web I discovered that the map function in python is used differently. Here is what an arduino map function would look like "map(val, 0, 180, 0, 90)". This would take the integer "val" which will be between 0 and 180 and convert it to a number between 0 and 90. I could not find the mathematical formula that the arduino uses to do this so my question is how can I do this in python either mathematically or using a function?

jes1510
01-29-2010, 11:03 PM
From the map function documentation on Arduino.cc :
Appendix

For the mathematically inclined, here's the whole function
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;
}