A class that reads the states of a button matrix.
More...
#include <AH/Hardware/ButtonMatrix.hpp>
|
virtual void | onButtonChanged (uint8_t row, uint8_t col, bool state)=0 |
| The callback function that is called whenever a button changes state. More...
|
|
void | setPrevState (uint8_t col, uint8_t row, bool state) |
|
template<uint8_t nb_rows, uint8_t nb_cols>
class AH::ButtonMatrix< nb_rows, nb_cols >
A class that reads the states of a button matrix.
- Template Parameters
-
nb_rows | The number of rows in the button matrix. |
nb_cols | The number of columns in the button matrix. |
Definition at line 23 of file ButtonMatrix.hpp.
◆ ButtonMatrix()
Construct a new ButtonMatrix object.
- Parameters
-
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 10 of file ButtonMatrix.ipp.
◆ ~ButtonMatrix()
◆ begin()
Initialize (enable internal pull-up resistors on column pins).
Definition at line 41 of file ButtonMatrix.ipp.
◆ update()
Scan the matrix, read all button states, and call the onButtonChanged callback.
Definition at line 17 of file ButtonMatrix.ipp.
◆ getPrevState()
bool getPrevState |
( |
uint8_t |
col, |
|
|
uint8_t |
row |
|
) |
| |
Get the state of the button in the given column and row.
- Note
- No bounds checking is performed.
Definition at line 69 of file ButtonMatrix.ipp.
◆ onButtonChanged()
virtual void onButtonChanged |
( |
uint8_t |
row, |
|
|
uint8_t |
col, |
|
|
bool |
state |
|
) |
| |
|
privatepure virtual |
The callback function that is called whenever a button changes state.
- Parameters
-
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. |
◆ positionToBits()
uint8_t positionToBits |
( |
uint8_t |
col, |
|
|
uint8_t |
row |
|
) |
| |
|
inlinestaticprivate |
◆ bitsToIndex()
uint8_t bitsToIndex |
( |
uint8_t |
bits | ) |
|
|
inlinestaticprivate |
◆ bitsToBitmask()
uint8_t bitsToBitmask |
( |
uint8_t |
bits | ) |
|
|
inlinestaticprivate |
◆ setPrevState()
void setPrevState |
( |
uint8_t |
col, |
|
|
uint8_t |
row, |
|
|
bool |
state |
|
) |
| |
|
private |
◆ prevRefresh
unsigned long prevRefresh = 0 |
|
private |
◆ prevStates
uint8_t prevStates[(nb_cols *nb_rows+7)/8] |
|
private |
◆ rowPins
◆ colPins
The documentation for this class was generated from the following files: