|
|
| Button () |
| | Default constructor for Button. Does not initialize board hardware. Call begin() to set up the button pin.
|
| void | begin (uint8_t pin) |
| | Reads the debounced state of the button.
|
| uint8_t | read () |
| | Initializes the Button with the specified pin and mode.
|
| uint8_t | read_raw () |
| | Reads the raw state of the input pin without debouncing.
|
| uint8_t | has_changed () |
| | Checks if the button state has changed since the last read.
|
| void | set_callback_on_toggle (void(*callback_function)()) |
| | Sets a callback function to be called when the button state toggles-either pressed or released.
|
| void | set_callback_on_press (void(*callback_function)()) |
| | Sets a callback function to be called when the button is pressed.
|
| void | set_callback_on_release (void(*callback_function)()) |
| | Sets a callback function to be called when the button is released.
|
| void | set_debounce_ms (uint16_t debounce_ms) |
| | Sets the debounce period for the button. Debouncing refers to checking the button state over a short period to avoid false triggering due to mechanical noise.
|
| void | set_mode (uint8_t button_mode) |
| | Sets the button mode to either standard or toggle. Toggle mode triggers the button state only on presses. Standard will trigger callbacks on both press and release.
|
|
void | set_invert () |
| | Inverts the button state logic. When inverted, a pressed button reads as released and vice versa. Not sure why you want this, but it's here if you need it.
|
|
void | clear_invert () |
| | Clears the invert flag, restoring normal button state logic.
|
Button class for handling digital input buttons.
The Button class provides an interface for reading and managing digital input buttons. It supports debouncing, state change detection, and callback functions for button events such as press, release, and toggle. Buttons can be configured in standard or toggle mode, and their state can be inverted if needed. Here's an example of how to instantiate and configure a Button:
#define module_driver
#include "stepdance.hpp"
void setup() {
dance_start();
}
void onButtonD1Release() {
Serial.println("Button D1 Released");
}
void onButtonD2Toggle() {
Serial.println("Button D2 Toggled");
}
void loop(){
dance_loop();
}