skotl
Forum Supporter
- Messages
- 9,685
- Location
- Edinburgh, UK
Here's my version of map() for floats:
And it in use to convert the ADC's 0-1024 to a voltage between 1V and 15V
float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
And it in use to convert the ADC's 0-1024 to a voltage between 1V and 15V
myData.voltage = floatMap(static_cast<float>(sensor), 0, 1024, 1, 15);
Serial.printf("Reading = %d, voltage = %f\n", sensor, myData.voltage);