I am trying to change an analogue pin (A0=PIN_HOLD) on the fly but running into an issue. The pin is initially set to an output in setup() and held high - no problem. In a function I then change it to an input and perform and A/D read - again no problem and I get the expected value.
I then try set it back to an output and take it high again but the pin just stays as an input.
If I comment out the analogRead line the pin will happily switch from input to output repeatedly, it just won't play ball after performing an A/D read.
Any ideas very welcome?
Code: Select all
pinMode(PIN_HOLD, INPUT); //Make the power hold pin an input
delay(20); // probably not needed
AD_Val = analogRead(PIN_HOLD); //Perform an A/D read to check for switch activity
delay(20);
pinMode(PIN_HOLD, OUTPUT); //turn the pin back to an output to maintain the power
digitalWrite(PIN_HOLD, HIGH);
Thanks