Buttons with analog inputs

Hi,

first of all I let you know that i am aware that the best way to implement a button is by using a digital Input. Unfortunately in my project all digital Pins on my board are used and I need to use some of the open analog inputs for my needed buttons.

Now my question: What is the best way to connect the buttons to the analog pins? (which resistors should I use etc.). And what is the best way to get the actual press-state in the loop-function?

Thank you for your answers!

Most of "analog" pins can be used as a digital. Which board do you have and how many "digital" pins do you need?

The analog inputs on Uno, Nano*, Mega, and the like, are digital pins with analog input as a special function. Use them like any other digital pins including internal pullups.

Which Arduino board are you using?

*A6 and A7 on a Nano are analog only.

Most of "analog" pins can be used as a digital.

Oh i didnt't know that!

I am using an Arduino Mega and am using all of the 54 digital Pins

Use the analog pins the same as digital pins.
For instance:

const byte buttonPin = A0;

void setup()
{
    pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{
    boolean buttonState = digitalRead(buttonPin);
}

Thanks everyone, I now know what to do!

ALL 16 analog pins on a Mega can be used as digital pins.