mapFloat(): Arduino's map() function extended to allow float variables

A function to extend range mapping to float/double variables.


// map one numerical span to another with floating point values
double mapFloat (double x, double in_min, double in_max, double out_min, double out_max) {
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

EX:  map an ADC range to normalized decimal:

    x_norm = mapFloat(adc_val, 0, 4095,  0.00, 1.00);



Comments

Popular posts from this blog

Using the SSD1306 Text/Graphics OLED Display module

Add the Compile Time and Date to your C++ or Arduino source code

Generate a CRC for NMEA Strings, Arduino Function