Skip to content

These module docs are in beta and may be incomplete.

modm:ui:button: Debouncing Buttons

The modm::ButtonGroup class is able to debounce eight buttons at the same time. The buttons have to be low-active. If this isn't the case invert their signal before passing it to the update() method.

The update() method needs to be called periodically for example every 10ms. Preferred in a timer interrupt function.

The detection for long or repeated presses works only correctly for one key at a time. This constraint only applies to buttons listed in the mask variable.

Mode 1:

                 Timeline ---->
                      __      _________________      __
getState()       ____/  \____/                 \____/  \____
isPressed()      ----X-------X----------------------X-------
isRepeated()     --------------------X--X--X--X-------------
isReleased()     -------X----------------------X-------X----
                             |       |__|__|
                             |_______| \ /
                                  \    interval

Mode 2:

                      __      _________________      __
getState()       ____/  \____/                 \____/  \____
isPressedShort() -------X------------------------------X----
isPressedLong()  --------------------X----------------------
isReleased()     -------X----------------------X-------X----

This implementation is based on the C functions written by Peter Dannegger (see


// Class
class modm::Button< typename PIN  >;
class modm::ButtonGroup< typename T=uint8_t >;


modm:ui:button modm_ui_button modm: ui: button modm_architecture_atomic modm: architecture: atomic modm_ui_button->modm_architecture_atomic modm_ui modm: ui modm_ui_button->modm_ui