I am trying to map the value of an analogRead from a potentiometer between 0-1. So I do:
float inverse_value = 1.0f / (float)analogRead( pot_pin )
But when the analogRead of the potentiometer is at 0, the inverse is 0 (which is correct), but when the analogRead is at 1023, the inverse becomes 0.0009775170.
Am I doing the divide correctly or what?
All the circuit is connected correctly. And the Arduino is running properly (I get no errors when uploading).
What you want to do, is probably this:
Assuming the max position is 1023.
That way, 0 to 1023 will be mapped as 0 to 1.
For example, when the potentiometer is in the middle position (512), it becomes this:
Which is about
0.5, and probably what you want to get.