# using pins A6 and A7 of arduino pro mini to read push button state

• Hi all,

so I run out of pins in my project where I use arduino pro mini. After 2 days of thinking I realised that my arduino has two more not used pins, but the are only for ADC. But hey, I just want to read a push button state (pressed or released). So I figured out that I will add a pull up resistor to this pins and just use analogRead for those pins and just do:

so is there any drawbacks to this solution ? I would imagine that analogRead would be slower than digitalRead, is there a way to make it faster ? I just need to know if the button is pressed or not.

• @rozpruwacz I am not sure if analogRead is slower but if it is, it will not make a difference when reading button presses, unless you are able to click many thousand times per second.

You can perform a digitalRead on an analog pin if you want to though, see https://www.arduino.cc/en/Reference/DigitalRead

One thing to remember: there is no internal pullup on A6 and A7, so you'll have to add your own external pullup.

• own external pullu

from the documentation it takes 100us for analog read, so its about 800 instructions for single read when running at 8MHz. Doing it in the main loop in every iteration for couple of pins will make a difference. Of course I will try first as simple as possible, but i'm worried that my node which acts as a repeater will not do its reapeter job very well ...

• @rozpruwacz sending a single message on nrf24 takes about 1ms, which is 10x the time it takes to do an analogRead (1ms = 1,000 us). So unless you need to check the button more than several thousand times per second you're going to be fine.

Quick calculation example: let's say you have 10 buttons and you want to check each them 50 times per second (which is much faster than a human can react, normal reaction time is about 1/10 to 1/20 second). That would require checking 10 * 50 * 100us = 50,000us = 50 ms. You'll still have 950ms to do everything else. So even an extreme case would not be a problem.

• ok, that is fair enough didn't know the time needed to send message on nrf24.

• Maybe you could somehow bond your buttons and whatever else to the same interrupt pin, and then sort out after-the-fact what triggered the interrupt after the interrupt occurs? Then you wouldn't need to waste all that time polling.

• You can perform a digitalRead on an analog pin if you want to though, see https://www.arduino.cc/en/Reference/DigitalRead
Not on A6/A7, they are exclusively analog pins.

1

10

1

2

1

2