Arduino

ButtonAPI DOCUMENTATION

Read and debounce buttons and switches.

See Example  Public Methods  Release Notes
Overview

Read and debounce buttons and switches without delay or interrupts. React to button events with the onPressed() and onReleased() commands. Control debounce time with setDebounceTimeout().

This library sets each button up as input_pullup by default, allowing you to wire the button to any digital input and ground. Input_pullup can be disabled by passing an optional flag to the constructor() and wiring the button with your own resistor.

Example Wiring
Example SketchArduinoC++
Public Methods

RBD::Button constructor(pin, [input_pullup])

Create a new button and pass in the Arduino pin number. This library will default to input_pullup and invert the button readings to simplify wiring for you. Pass in the second [optional] parameter as false to disable input_pullup.

EXAMPLE SKETCH
button
.setDebounceTimeout(value)

Provide an unsigned long value greater than zero to set the debounce time in milliseconds. Most mechanical buttons will flip between on and off very quickly before settling in the correct state after being pressed or switched. Adjusting the debounce timeout will help remove these extra state-change events.

EXAMPLE SKETCH
button
.invertReading()

Flip the value of the raw button state reading so when the button isPressed() it will register as isReleased(), and vice versa. This method changes the behavior for onPressed() and onReleased() as well.

EXAMPLE SKETCH
button
.isPressed()

Returns true while the button is being pressed, or is on. Returns false while the button is not being pressed, or is off.

This method is good for real-time actions that must fire many times during a button press. Use the onPressed() event to fire only one action on each button press.

EXAMPLE SKETCH
button
.isReleased()

Returns true while the button is released, or is off. Returns false while the button is being pressed, or is on.

This method is good for real-time actions that must fire many times while the button is not pressed. Use the onReleased() event to fire only one action on each button release.

EXAMPLE SKETCH
button
.onPressed()Event

This will return true only once, after the button has been pressed (and debounced). The button must be released and then pressed again for this method to return true again.

EXAMPLE SKETCH
button
.onReleased()Event

This will return true only once, after the button has been released (and debounced). The button must be pressed and then released again for this method to return true again.

EXAMPLE SKETCH