Hi, I am using this map function. VAL= map(a1,0,90,80,30) . When a1 =0, val=80. when a1 =90 val=30. I am getting when a1=37.69, VAL=60. The map function only works in integers so a1 would be seen as 38.
Can anybody give me the maths here to calculate VAL from the value of a1? I cannot see how it is calculated.
Thanks.
Use this variation which can handle float
float mapfloat(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;
}
a1 would be "seen" as 37. Going from float to integer truncates.
a7
you should read the Arduino reference, it is explained in
https://docs.arduino.cc/language-reference/en/functions/math/map/
I'd suggest you dont use the map function. Where did you hget those values?
using my figures and the maths I am getting the 60 return. thanks for the extra accuracy although for my purposes integers are accurate enough. It is no wonder I could not figure out the maths for getting 60. 37 is slightly more accurate than 38 as suggested by alto777.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.