There are many ways of reading switches, and one of them is using ADC pins. The advantages of this method is that it uses very low pin count compared to other methods, and all is needed are switches, resistors and an ADC (analog to digital converter). With a 10bit ADC, at least 20 switches can be used per pin.
To read the buttons the conventional way where every button is connected directly to a GPIO pin, check out this other library https://www.programming-electronics-diy.xyz/2021/01/button-debouncing-library-for-avr.html.
Library Features
- Supports multiple groups of buttons on different ADC pins
- Ability to read combination of multiple button press on different ADC pins
- Can have different number of buttons on each pin
- Check if a button was pressed for a certain amount of time
- Timer 2 and ADC is setup by default
Reading buttons using ADC (configuration #1)
Fig. 1 Reading buttons using ADC (configuration #1) |