3

I can't figure out the terminology to search for the function I want:

Anrduino has a map(value,inLo,inHi,outLo,outHi) function that takes a value within IN range and returns the value with the same ratio mapped to the OUT range. For example map(5,0,6,200,380) returns 350 because the value 5 in a range of 0-6 is 5/6 and 5/6 of the range from 200 to 380 is 350.

I can write my own function in Excel but I am guessing there is something built in.

Playing with GAS
  • 565
  • 3
  • 10
  • 18

3 Answers3

1

Very good explanation is given by James Ramsden here: http://james-ramsden.com/map-a-value-from-one-number-scale-to-another-formula-and-c-code/

Essentially if one scale is from a0 to a1 and other scale is from b0 to b1 and you want to map the value a to some value of b. The equation is:

enter image description here

Put in the same terms as the original question:

map(value, inLo, inHi, outLo, outHi) = outLo + (outHi - outLo) * (value - inLo) / (inHi - inLo)

JDMc
  • 103
  • 5
wilkas
  • 1,161
  • 1
  • 12
  • 34
0

Actually Charles Williams answer doesnt quite address the equivalent Arduino 'Map' function. A more correct formula is: =((value-inLo)/(inhi-inlo))*(outhi-outlo)

Mij
  • 1
0

You mean correct formula is : (from arduino.cc/en/Reference/Map) 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;}

(you forgot +out_min at the end)

douardo
  • 697
  • 6
  • 6