I’m newbie in micropython
How to write map function as in Arduino?
mappedValue = map(moistureValue,AirValue,WaterValue, 0, 100);
All what I can do in micropython as following:
from machine import Pin, ADC
from time import sleep
moistureValue= ADC(Pin(A0))
moistureValue.atten(ADC.ATTN_11DB)
2 Answers
Hi.
There isn’t such function in MicroPython. But you can define your own function to do that.
Declare the function:
def scale_value(value, in_min, in_max, out_min, out_max): scaled_value = (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min return scaled_value
Then, just call the function with the desired parameters and it will return the mapped value.
I hope this helps.
Regards,
Sara