trouble reading analog pins with digitalRead()

The following prints 1 for A0 and A1 whether left floating or tied to GND. Any advice on how to fix it?

Thanks!

char* analogInputs[] = {"A0", "A1"};

void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
}

void loop()
{
for (int i = 0; i < 2; i++)
{
int pinState = (digitalRead(atoi(analogInputs*)));*

  • Serial.print("A");*
  • Serial.print(i);*
  • Serial.print(": ");*
  • Serial.println(pinState);*
  • delay(500);*
  • }*
    }

That became a fine example why you need to use code tag. </>
Compiler doesn't like italic.
Have you tried to add a line Serial.print(atoi(analogInputs[i]));
Just to make sure you are reading the right pin.

A0 and A1 aren't char strings, they're defined constants that are substituted with the right pin number when you compile the code.

uint8_t analogInputs[] = {A0, A1};

Then just use:

digitalRead( analogInputs[i] );

Thanks so much for the help everyone especially Jiggy-Ninja, that fixed it! Will remember to check the constants in the header file next time.