#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 23 of file ButtonMatrix.hpp.
Public Member Functions | |
ButtonMatrix (const PinList< NumRows > &rowPins, const PinList< NumCols > &colPins) | |
Construct a new ButtonMatrix object. More... | |
void | begin () |
Initialize (enable internal pull-up resistors on column pins). More... | |
void | update () |
Scan the matrix, read all button states, and call the onButtonChanged callback. More... | |
bool | getPrevState (uint8_t col, uint8_t row) |
Get the state of the button in the given column and row. More... | |
void | setDebounceTime (unsigned long debounceTime) |
Configure the debounce time interval. More... | |
unsigned long | getDebounceTime () const |
Get the debounce time. More... | |
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. More... | |
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 |
ButtonMatrix | ( | 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. |
Definition at line 9 of file ButtonMatrix.ipp.
void begin |
Initialize (enable internal pull-up resistors on column pins).
Definition at line 43 of file ButtonMatrix.ipp.
void update |
Scan the matrix, read all button states, and call the onButtonChanged callback.
Definition at line 16 of file ButtonMatrix.ipp.
bool getPrevState | ( | uint8_t | col, |
uint8_t | row | ||
) |
Get the state of the button in the given column and row.
Definition at line 74 of file ButtonMatrix.ipp.
|
inline |
Configure the debounce time interval.
Only one button can change in each debounce interval. Time in milliseconds.
Definition at line 61 of file ButtonMatrix.hpp.
|
inline |
Get the debounce time.
Definition at line 65 of file ButtonMatrix.hpp.
|
protecteddelete |
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. |
|
inlinestaticprivate |
Definition at line 55 of file ButtonMatrix.ipp.
|
inlinestaticprivate |
Definition at line 63 of file ButtonMatrix.ipp.
|
inlinestaticprivate |
Definition at line 69 of file ButtonMatrix.ipp.
|
private |
Definition at line 81 of file ButtonMatrix.ipp.
|
private |
Definition at line 87 of file ButtonMatrix.hpp.
|
private |
Definition at line 88 of file ButtonMatrix.hpp.
|
private |
Definition at line 89 of file ButtonMatrix.hpp.
|
private |
Definition at line 91 of file ButtonMatrix.hpp.
|
private |
Definition at line 92 of file ButtonMatrix.hpp.