Last active
March 5, 2019 20:14
-
-
Save sapher/20c5ffa30c7f75bd38d0 to your computer and use it in GitHub Desktop.
Map function for PIC microcontroller that map a value from a range to another range
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
uint16_t map(uint16_t value, uint16_t fS, uint16_t fE, uint16_t tS, uint16_t tE) { | |
return ((long)(value - fS) * (long)(tE - tS)) / ((fE - fS) + tS); | |
} | |
// map(512, 0, 1024, 0, 512); > 127 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice snippet
shouldn't it be: