A class that reads the states of a button matrix. More...
#include <AH/Hardware/ButtonMatrix.hpp>
Public Member Functions | |
ButtonMatrix (const PinList< nb_rows > &rowPins, const PinList< nb_cols > &colPins) | |
Construct a new ButtonMatrix object. More... | |
virtual | ~ButtonMatrix ()=default |
Destructor. 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... | |
Private Member Functions | |
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) |
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 | prevRefresh = 0 |
uint8_t | prevStates [(nb_cols *nb_rows+7)/8] |
const PinList< nb_rows > | rowPins |
const PinList< nb_cols > | colPins |
A class that reads the states of a button matrix.
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 | ( | const PinList< nb_rows > & | rowPins, |
const PinList< nb_cols > & | 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 10 of file ButtonMatrix.ipp.
|
virtualdefault |
Destructor.
void begin | ( | ) |
Initialize (enable internal pull-up resistors on column pins).
Definition at line 41 of file ButtonMatrix.ipp.
void update | ( | ) |
Scan the matrix, read all button states, and call the onButtonChanged callback.
Definition at line 17 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 69 of file ButtonMatrix.ipp.
|
privatepure virtual |
The callback function that is called whenever a button changes state.
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. |
Implemented in MIDIButtonMatrix< BankAddress, Sender, nb_rows, nb_cols >, MIDIButtonMatrix< ManyMatrixAddresses< NumBanks, nb_rows, nb_cols >, DigitalCCSender, nb_rows, nb_cols >, MIDIButtonMatrix< ManyMatrixAddresses< NumBanks, nb_rows, nb_cols >, DigitalNoteSender, nb_rows, nb_cols >, MIDIButtonMatrix< MatrixAddress< nb_rows, nb_cols >, DigitalNoteSender, nb_rows, nb_cols >, MIDIButtonMatrix< MatrixAddress< nb_rows, nb_cols >, DigitalCCSender, nb_rows, nb_cols >, MIDIButtonMatrix< Sender, nb_rows, nb_cols >, MIDIButtonMatrix< DigitalCCSender, nb_rows, nb_cols >, and MIDIButtonMatrix< DigitalNoteSender, nb_rows, nb_cols >.
|
inlinestaticprivate |
Definition at line 52 of file ButtonMatrix.ipp.
|
inlinestaticprivate |
Definition at line 59 of file ButtonMatrix.ipp.
|
inlinestaticprivate |
Definition at line 64 of file ButtonMatrix.ipp.
|
private |
Definition at line 75 of file ButtonMatrix.ipp.
|
private |
Definition at line 82 of file ButtonMatrix.hpp.
|
private |
Definition at line 83 of file ButtonMatrix.hpp.
|
private |
Definition at line 85 of file ButtonMatrix.hpp.
|
private |
Definition at line 86 of file ButtonMatrix.hpp.