Switch reading: analogRead gives 1023 or 0, digitalRead always 0 .

I'm trying to connect a switch to the A6 pin, but when I try to read the pin status, I always get the '0' signal.
When I use the analogRead method, it gives 1023, and when measuring the pin voltage, it gets the 5V or 0V's
What's my mistake? (btw, I'm using this analog pin because all the digital ones are already in use...)
With the code below, I'm just trying to show the pinstatus.
I'm using an external pullup resistor (10k)

#include <Wire.h>

#include <LiquidCrystal.h>

int lcdOut = A3;
int lcdRS = 4;
int lcdEnable = 5;
int lcdD4 = 6;
int lcdD5 = 7;
int lcdD6 = 8;
int lcdD7 = 12;
LiquidCrystal lcd(lcdRS, lcdEnable, lcdD4, lcdD5, lcdD6, lcdD7);

void setup()
{
  Wire.begin();
  Serial.begin(9600);

  pinMode(lcdOut,OUTPUT);
  digitalWrite(lcdOut,LOW);
  lcd.begin(16,2);
  Serial.println("wachten");
  delay(1000);
  Serial.println("ok");
  digitalWrite(lcdOut,HIGH);
  delay(100);
  lcd.display();
  pinMode(A6,INPUT);
  digitalWrite(A6, HIGH);

}

void loop()
{
  lcd.print(analogRead(A6));
  lcd.print(" ");
  lcd.print(digitalRead(A6));
  Serial.println(analogRead(A6));
  Serial.println(digitalRead(A6));
  delay(10);
  lcd.clear();
}

Set pinMode. (A6, INPUT);
And just use it as a digital pin.
Lose the analogRead.

Tested it with both:

void loop()
{
  lcd.print(analogRead(A6));
   Serial.println(analogRead(A6));
  delay(10);
  lcd.clear();
}

with 0(button pressed) or 1023(button not pressed) as result;
and

void loop()
{
  lcd.print(digitalRead(A6));
   Serial.println(digitalRead(A6));
  delay(10);
  lcd.clear();
}

with always 0 as result...
I'm assuming that the 1023 on the analog measurement represents a voltage that refers to logic 1? :confused:

'm assuming that the 1023 on the analog measurement represents a voltage that refers to logic 1?

Yes that is right.

Then why do I get a zero-signal when the pin is high?...

Ward123:
Then why do I get a zero-signal when the pin is high?...

A6 and A7 are only inputs available to the mux in front of the ADC. There is no digital hardware behind the pins.

Ohw, with that information, the gray 'digital pins' on the pinout diagram are explained...
Its quiet easy to work around I guess, just if(analogRead>512) instead of digitalRead(..) will work in my case.
Thanks for pointing it out. :slight_smile:

Maybe if you'd said it was a Nano earlier. . .

AWOL:
Maybe if you'd said it was a Nano earlier. . .

True but he did give us a clue talking about A6.

I only realised this when I dragged my Arduino out and was actually going to try it.

Sorry, next time, I'll mention the arduino I'm using, at the topic start.
Another thing learned :slight_smile: