The analogRead command will not work correctly if a pin has been previously set to an output, so if this is the case, set it back to an input before using analogRead. Similarly if the pin has been set to HIGH as an output, the pullup resistor will be set, when switched back to an input.
pinMode(D14, INPUT);digitalWrite (D14, LOW);
The Atmega datasheet also cautions against switching analog pins in close temporal proximity to making A/D readings (analogRead) on other analog pins. This can cause electrical noise and introduce jitter in the analog system. It may be desirable, after manipulating analog pins (in digital mode), to add a short delay before using analogRead() to read other analog pins.
So, it means that I have to add the code in the void setup every time if I am dealing with analog pins ?
Why do it need to read twice ?
This is because sometimes I am not sure about the previous use of the analog pin.
It's reading is inaccurate ?
Just sometimes I may not be using the board for too long time. So I have forgotten what is the sketch that I had uploaded previously.
pinMode(D14, [b]INPUT[/b]);digitalWrite (D14, LOW);
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16