AN_INPUT Ok to use?

analogRead() sets the pin mode implicitly to AN_INPUT and if you had set another pin mode prior to the first call to analogRead() the pin will be set back to what it was. But you shouldn’t need to keep changing the pin mode after that anymore.

try this

void setup()
{
  pinMode(A2, INPUT_PULLUP);  // set this once as default state for the pin
}

void loop()
{
  if(digitalRead(A2))
  { // A2 is set as INPUT_PULLUP
    Serial.println(analogRead(A2));  // will be temporarily changed to AN_INPUT
    // and now should be back to INPUT_PULLUP 
  }
  delay(1000);
}

But why would you need digitalRead() anyway?
How does your circuitry look that you need to use INPUT_PULLUP and not just stick with analogRead() permanently?

1 Like