Dealing with buttons


I need some help dealing with buttons.

I am building a rtc with multiplexed display and would like to use a 5 position button (Parallax in particular)

When power is applied the clock would come on and display the stored time on the RTC. I would like to use the button to change the stored time on the rtc.

Holding the button down for two seconds would allow you to set the time.

My question is what is the best way to poll for button presses and and what is the best way to monitor for button press duration also what is the best way to deal with multiple buttons?

Any help or insight will be greatly appreciated,


For starters, you can save some external components by wiring your buttons from GND to whatever (digital) pins you want to use, using INPUT_PULLUP in your pinMode() statements, and detecting the Pressed state when reading a LOW.

As for the rest, have a look at Nick Gammon's excellent tutorial at

That will tell you everything you need to know about reading, debouncing, and timing the duration of switch/button presses.


I will peruse the information at the link provided.

Thank you for your help,