I've got a servo which turns opposite to the number I get from a program. The numbers I get from the program are between 37...113. I need to convert the 37 to its opposite side. So 37 becomes 113, 38 becomes 112, and so on. 75 stays at 75 because that's the mid point.
Do any of you know of a way to calculate this? This sounds like simple math, but I can't figure it out. I don't want to use a look-up table because the range may change.
public int reverseNumber(int num, int min, int max) {
return (max + min) - num;
}
reverseNumber(37, 37, 113); // returns 113
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With