#include <AH/Hardware/ButtonMatrix.hpp>
A class that reads the states of a button matrix.
NumRows | The number of rows in the button matrix. |
NumCols | The number of columns in the button matrix. |
Definition at line 20 of file ButtonMatrix.hpp.
Public Member Functions | |
ButtonMatrix (const PinList< NumRows > &rowPins, const PinList< NumCols > &colPins) | |
Construct a new ButtonMatrix object. | |
void | begin () |
Initialize (enable internal pull-up resistors on column pins). | |
void | update () |
Scan the matrix, read all button states, and call the onButtonChanged callback. | |
bool | getPrevState (uint8_t col, uint8_t row) |
Get the state of the button in the given column and row. | |
void | setDebounceTime (unsigned long debounceTime) |
Configure the debounce time interval. | |
unsigned long | getDebounceTime () const |
Get the debounce time. | |
Protected Member Functions | |
void | onButtonChanged (uint8_t row, uint8_t col, bool state)=delete |
The callback function that is called whenever a button changes state. | |
Private Member Functions | |
void | setPrevState (uint8_t col, uint8_t row, bool state) |
Static Private Member Functions | |
static uint8_t | positionToBits (uint8_t col, uint8_t row) |
static uint8_t | bitsToIndex (uint8_t bits) |
static uint8_t | bitsToBitmask (uint8_t bits) |
Private Attributes | |
unsigned long | debounceTime = BUTTON_DEBOUNCE_TIME |
unsigned long | prevRefresh = 0 |
uint8_t | prevStates [(NumCols *NumRows+7)/8] |
const PinList< NumRows > | rowPins |
const PinList< NumCols > | colPins |
Construct a new ButtonMatrix object.
rowPins | A list of pin numbers connected to the rows of the button matrix. ⚠ These pins will be driven LOW as outputs (Lo-Z). |
colPins | A list of pin numbers connected to the columns of the button matrix. These pins will be used as inputs (Hi-Z), and the internal pull-up resistor will be enabled. |
Initialize (enable internal pull-up resistors on column pins).
Scan the matrix, read all button states, and call the onButtonChanged callback.
Get the state of the button in the given column and row.
Configure the debounce time interval.
Only one button can change in each debounce interval. Time in milliseconds.
Definition at line 58 of file ButtonMatrix.hpp.
Get the debounce time.
Definition at line 62 of file ButtonMatrix.hpp.
The callback function that is called whenever a button changes state.
Implement this in the derived class.
row | The row of the button that changed state. |
col | The column of the button that changed state. |
state | The new state of the button. |
|
private |
Definition at line 84 of file ButtonMatrix.hpp.
Definition at line 85 of file ButtonMatrix.hpp.
Definition at line 86 of file ButtonMatrix.hpp.
Definition at line 88 of file ButtonMatrix.hpp.
Definition at line 89 of file ButtonMatrix.hpp.