m5stack / M5Stack_MicroPython

MicroPython for ESP32 with psRAM support
Other
230 stars 53 forks source link

map_value() #7

Closed FlorianPoot closed 5 years ago

FlorianPoot commented 5 years ago

Is the function map_value() from m5stack.py working ?

Maybe I'm using it badly but it always give me incorrect number.

Ex: map_value(value, 3000, 4100, 0, 6) return always 6 independently of value.

Here is a function that I think is more correct

def map_value(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
EeeeBin commented 5 years ago

You are right...