Control Surface pin-t-adl
MIDI Control Surface library for Arduino
Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ButtonMatrix< Derived, NumRows, NumCols > Class Template Reference

#include <AH/Hardware/ButtonMatrix.hpp>

Detailed Description

template<class Derived, uint8_t NumRows, uint8_t NumCols>
class AH::ButtonMatrix< Derived, NumRows, NumCols >

A class that reads the states of a button matrix.

Template Parameters
NumRowsThe number of rows in the button matrix.
NumColsThe number of columns in the button matrix.

Definition at line 23 of file ButtonMatrix.hpp.

+ Collaboration diagram for ButtonMatrix< Derived, NumRows, NumCols >:

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
 

Constructor & Destructor Documentation

◆ ButtonMatrix()

ButtonMatrix ( const PinList< NumRows > &  rowPins,
const PinList< NumCols > &  colPins 
)

Construct a new ButtonMatrix object.

Parameters
rowPinsA list of pin numbers connected to the rows of the button matrix.
These pins will be driven LOW as outputs (Lo-Z).
colPinsA 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.

Member Function Documentation

◆ begin()

void begin

Initialize (enable internal pull-up resistors on column pins).

Definition at line 43 of file ButtonMatrix.ipp.

◆ update()

void update

Scan the matrix, read all button states, and call the onButtonChanged callback.

Definition at line 16 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 74 of file ButtonMatrix.ipp.

◆ setDebounceTime()

void setDebounceTime ( unsigned long  debounceTime)
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.

◆ getDebounceTime()

unsigned long getDebounceTime ( ) const
inline

Get the debounce time.

Definition at line 65 of file ButtonMatrix.hpp.

◆ onButtonChanged()

void onButtonChanged ( uint8_t  row,
uint8_t  col,
bool  state 
)
protecteddelete

The callback function that is called whenever a button changes state.

Implement this in the derived class.

Parameters
rowThe row of the button that changed state.
colThe column of the button that changed state.
stateThe new state of the button.

◆ positionToBits()

uint8_t positionToBits ( uint8_t  col,
uint8_t  row 
)
inlinestaticprivate

Definition at line 55 of file ButtonMatrix.ipp.

◆ bitsToIndex()

uint8_t bitsToIndex ( uint8_t  bits)
inlinestaticprivate

Definition at line 63 of file ButtonMatrix.ipp.

◆ bitsToBitmask()

uint8_t bitsToBitmask ( uint8_t  bits)
inlinestaticprivate

Definition at line 69 of file ButtonMatrix.ipp.

◆ setPrevState()

void setPrevState ( uint8_t  col,
uint8_t  row,
bool  state 
)
private

Definition at line 81 of file ButtonMatrix.ipp.

Member Data Documentation

◆ debounceTime

unsigned long debounceTime = BUTTON_DEBOUNCE_TIME
private

Definition at line 87 of file ButtonMatrix.hpp.

◆ prevRefresh

unsigned long prevRefresh = 0
private

Definition at line 88 of file ButtonMatrix.hpp.

◆ prevStates

uint8_t prevStates[(NumCols *NumRows+7)/8]
private

Definition at line 89 of file ButtonMatrix.hpp.

◆ rowPins

const PinList<NumRows> rowPins
private

Definition at line 91 of file ButtonMatrix.hpp.

◆ colPins

const PinList<NumCols> colPins
private

Definition at line 92 of file ButtonMatrix.hpp.


The documentation for this class was generated from the following files: