Here is my code, throttle comes out to -18 when I run the program, and when I do the math I get 77.941... which is what I'm looking for. I am programming it on an Atmega 328P using Arduino IDE on Windows 10.
The following example prints -18 and according to my calculations it should be 77.941:
int throttle = (((800 - 270) * 100) / 680);
Serial.println(throttle);
This is the visualized code:
throttle = (((throttleSensor - oldMinValue) * (newMax - newMin)) / (oldMax - oldMin));
I am trying to do this, Convert a number range to another range, maintaining ratio
Also, I should add, it works fine when the result is below 47, above that it flips to a negative number.