issued related to the map function

Hi there!

http://arduinobasics.blogspot.com.au/2012/07/arduino-basics-simple-arduino-serial.html ( sorry the link button is acting up)

Trial 3:

13  sensorVal = map(analogRead(A0),200,800,0,100);

In Trial 3: The analog readings that range from 200 to 800 are mapped to a range of 0 to 100. Therefore if the analog readings drop below 200, we will end up with a negative value for sensorVal.
If the analog readings go above 800, we will end up with a value greater than 100. For this particular example, my readings actually range from -33 to 137.

Therefore an Analog reading of 0 = -33
Analog reading of 200 = 0
Analog reading of 800 = 100
Analog reading of 1023 = 137

My questions are how does this guy get -33 and +137?

My other question is map() function equation wrong - Suggestions for the Arduino Project - Arduino Forum

has this map function been fixed yet?

Regards,

Thanks a lot.

 sensorVal = map(analogRead(A0),200,800,0,100);

If analog read of A0 returns a value between 200 and 800 then the output from the map function will be between 0 and 100.

If the analog read falls OUTSIDE the range of 200 to 800 then the output from the map function will also be outside the values of 0 to 100.

It's all relative.

siutoejai:
has this map function been fixed yet?

I wasn't aware it was broken.

Thanks both of you.

I understand the diagram and everything, but

I still do not know how to get -33 and + 127.(the calculation part)

Thanks.

did you look at the graph? The red line is what you are mapping. (I know it's not to scale and doesnt line up perfectly, that's what you get for 90 seconds in paint though...)

Analog input on the arduino range from 0 to 1023.

If you map something from 200 to 800 that doesn't change that there are still 1024 total steps available from the input.

If your map function makes 200 == 0 then would it not make some sense that <200 == <0? The inverse would also be true of 100 and 800...

Thanks for replying, both of you.

What a concept!, Actually checking something prior to posting a question.
I shall try to remember this prior to posting a dumb question that I might solve by removing my shoes and socks to unleash my calculator or have someone else think for me...

...

KenF:
I wasn't aware it was broken.

It is. @st42 posted the correct equation for integers (longs).