Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
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 20 of file ButtonMatrix.hpp.

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

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< NumRowsrowPins
 
const PinList< NumColscolPins
 

Constructor & Destructor Documentation

◆ ButtonMatrix()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
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.

Member Function Documentation

◆ begin()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
void begin ( )

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

◆ update()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
void update ( )

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

◆ getPrevState()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
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.

◆ setDebounceTime()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
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 58 of file ButtonMatrix.hpp.

◆ getDebounceTime()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
unsigned long getDebounceTime ( ) const
inline

Get the debounce time.

Definition at line 62 of file ButtonMatrix.hpp.

◆ onButtonChanged()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
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()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
static uint8_t positionToBits ( uint8_t col,
uint8_t row )
inlinestaticprivate

◆ bitsToIndex()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
static uint8_t bitsToIndex ( uint8_t bits)
inlinestaticprivate

◆ bitsToBitmask()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
static uint8_t bitsToBitmask ( uint8_t bits)
inlinestaticprivate

◆ setPrevState()

template<class Derived , uint8_t NumRows, uint8_t NumCols>
void setPrevState ( uint8_t col,
uint8_t row,
bool state )
private

Member Data Documentation

◆ debounceTime

template<class Derived , uint8_t NumRows, uint8_t NumCols>
unsigned long debounceTime = BUTTON_DEBOUNCE_TIME
private

Definition at line 84 of file ButtonMatrix.hpp.

◆ prevRefresh

template<class Derived , uint8_t NumRows, uint8_t NumCols>
unsigned long prevRefresh = 0
private

Definition at line 85 of file ButtonMatrix.hpp.

◆ prevStates

template<class Derived , uint8_t NumRows, uint8_t NumCols>
uint8_t prevStates[(NumCols *NumRows+7)/8]
private

Definition at line 86 of file ButtonMatrix.hpp.

◆ rowPins

template<class Derived , uint8_t NumRows, uint8_t NumCols>
const PinList<NumRows> rowPins
private

Definition at line 88 of file ButtonMatrix.hpp.

◆ colPins

template<class Derived , uint8_t NumRows, uint8_t NumCols>
const PinList<NumCols> colPins
private

Definition at line 89 of file ButtonMatrix.hpp.


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