Buttons

Available methods

Configuration

  • setPinMode(INPUT, DOWN) - The first parameter can be set to INPUT, INPUT_PULLUP or INPUT_PULLDOWN. If this method is not used, the default mode is INPUT_PULLUP and the internal pull-up resistor of the pin will be used. If the first parameter is set to INPUT, you will have to implement an external pull-down or pull-up resistor. You can then optionally set the second parameter to PULL_DOWN or PULL_UP.
  • setDelayedReleaseDuration(500) - Sets the amount of time for a delayed release (in milliseconds).
  • setMultiplexer(&mux) - Sets the multiplexer that the button subscribes to.
  • setGroup(&group) - Register the button to a group.

Core

  • process() - Polls the button and handles all its functionality (used in the loop method).
  • storePinState(state) - Store a pin state from an ISR or interrupt handler. Call this from a hardware interrupt (e.g. attachInterrupt) to feed the button a pin reading without blocking the interrupt context. The next call to process() will consume the stored state and apply debouncing and state change detection as normal.

Event handlers

  • setOnPress(handler) - Sets the onPress handler. Called when the button is pressed.
  • setOnRelease(handler) - Sets the onRelease handler. Called when the button is released.
  • setOnDelayedRelease(handler) - Sets the onDelayedRelease handler. Called when the button is released after a certain amount of time (default is 500ms).

State

  • isPressed() - Checks if the button is currently being pressed.
  • isReleased() - Checks if the button is currently not being pressed.
  • isEnabled() - Checks if the button is enabled.
  • isDisabled() - Checks if the button is disabled.
  • isMuxed() - Checks if the button is currently attached to a multiplexer.
  • isGrouped() - Checks if the button is currently added to a group.
  • enable() - Enables the button.
  • disable() - Disables the button.

Custom properties

  • setInteger("id", 0) - Define an integer. First parameter is the name, second is the value.
  • setString("name", "Button") - Define a string. First parameter is the name, second is the value.
  • setBoolean("active", true) - Define a boolean. First parameter is the name, second is the value.
  • getInteger("id") - Get the value of an integer.
  • getString("name") - Get the value of a string.
  • getBoolean("active") - Get the value of a boolean.
Previous
Using the library