void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
uint16_t q = mapValueToNewRange(900, 100, 900, 0, 1023);
Serial.println(q);
}
void loop() {
// put your main code here, to run repeatedly:
}
uint16_t mapValueToNewRange(uint16_t old_value, uint16_t oldMin, uint16_t oldMax, uint16_t newMin, uint16_t newMax) {
// Use long for intermediate calculations to avoid overflow
return (uint16_t)((long)(old_value - oldMin) * (newMax - newMin) / (oldMax - oldMin) + newMin); // Changed oldMin to newMin
}