Created
April 2, 2019 19:52
-
-
Save mfurquimdev/7258a5f57afb9afa77bb6d377dcca701 to your computer and use it in GitHub Desktop.
Mapping a range of values to another
This file contains hidden or 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
| # https://github.com/arduino/Arduino/issues/2466 | |
| def m (x, in_min, in_max, out_min, out_max): | |
| if ((in_max - in_min) > (out_max - out_min)): | |
| return (x - in_min) * (out_max - out_min+1) / (in_max - in_min+1) + out_min; | |
| else: | |
| return (x - 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