Skip to content

Instantly share code, notes, and snippets.

@nadavmatalon
Created October 12, 2016 15:13
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nadavmatalon/71ccaf154bc4bd71f811289e78c65918 to your computer and use it in GitHub Desktop.
Save nadavmatalon/71ccaf154bc4bd71f811289e78c65918 to your computer and use it in GitHub Desktop.
ARDUINO: MAP FLOAT FUNCTION
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;
}
@Kerlenton
Copy link

hello, for what using this function?

@nadavmatalon
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment