Created
October 12, 2016 15:13
-
-
Save nadavmatalon/71ccaf154bc4bd71f811289e78c65918 to your computer and use it in GitHub Desktop.
ARDUINO: MAP FLOAT FUNCTION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double mapf(double val, double in_min, double in_max, double out_min, double out_max) { | |
return (val - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I wrote this a long time ago but as best I remember this function maps a given double-type number from one range onto another range. So for example, if you give it the number 5, input range of 1-10, and output range of 1-20 it will return 10.
Hope this helps.