I think analogRead assumes the pin is configured as an input, so unless you make another pinMode call to set the pin back to be an input, the output will continue to be driven low.
Yes. Analog pins are input only, so there is no need, or ability, to set the mode of an analog pin. The analogRead() function knows that the analog pin is input.
PaulS:
Analog pins are input only, so there is no need, or ability, to set the mode of an analog pin. The analogRead() function knows that the analog pin is input.
Actually I've found that I do need to set the pinMode to input, else analogRead does not work.
Here is the code:
if (eResetData == ekReset) {
// Here you are pulling the capacitor low by making the
// ADC a digital output temporarirly
Serial.println ("Reset secondary...") ;
pinMode (ikAnalogReadPin, OUTPUT);
digitalWrite (ikAnalogReadPin, LOW) ;
delay (1250) ; // wait to make sure the cap is discharged?
pinMode (ikAnalogReadPin, INPUT); // Without this analogRead always returns 0
analogRead (ikAnalogReadPin) ; // do a dummy read to get the pin in the right state?
}
Note the penultimate statement. Without that analogRead does not work.
"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."
"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 I do need to set it to input (initial guess was wrong) and my guess that I should give time for the pin to "settle down" was right.
Actually I've found that I do need to set the pinMode to input, else analogRead does not work.
You only need to do this if you used the analog pin AS A DIGITAL PIN. Setting the mode of an analog pin is impossible. Setting the mode of that same pin AS A DIGITAL PIN is possible, and, when switching from analog to digital mode, or from digital mode to analog mode, required.