Update: Mabs has now been merged Mutila.

* * *

Introducing Mabs - a library for buttons and other inputs for Arduino microcontrollers.

I think many coders have the experience of writing the same code over and over for different projects - basic infrastructural pieces which are easy enough to put together that we never bother putting them into a proper library - we just write them from scratch for every project. Code for reading button inputs is one of those things - I must have written code to implement a debounced button a dozens of times or more. 

Mabs is an Arduino library which wraps up button and other input handling code into nice easy-to-use, well tested classes which can be easily used in your projects. The most commonly used class is the DebouncedButton, which protects the user from fluctuations in the read value around the time a button is pressed or released.

Mabs classes use a "time-slice" approach. An update() function is called frequently (typically from a sketch's loop() function), which updates the object's state and quickly returns. Other member function can then be called to test the state of the object (i.e. has a  button press been registered?). For many applications this is preferred to the naive debounced button implementation which blocks while some timer expires and repeatedly tests the state of the button's input pin.

A minimal example:

#include <DebouncedButton.h>

// Button connected to pin 3 in pullup mode
// i.e. ground pin to register a press
DebouncedButton button(3);

void setup()
    pinMode(13, OUTPUT); // the built-in LED on an Uno/Nano
    digitalWrite(13, LOW);

void loop()
    if (button.pushed()) {
        digitalWrite(13, HIGH);
        digitalWrite(13, LOW);

For more information, see the Mabs documentation, here.