Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
ButtonMatrix.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
6
8
19template <class Derived, uint8_t NumRows, uint8_t NumCols>
21 public:
36 const PinList<NumCols> &colPins);
37
41 void begin();
42
47 void update();
48
55
58 void setDebounceTime(unsigned long debounceTime) {
59 this->debounceTime = debounceTime;
60 }
62 unsigned long getDebounceTime() const { return debounceTime; }
63
64 protected:
76 void onButtonChanged(uint8_t row, uint8_t col, bool state) = delete;
77
78 private:
79 static inline uint8_t positionToBits(uint8_t col, uint8_t row);
80 static inline uint8_t bitsToIndex(uint8_t bits);
81 static inline uint8_t bitsToBitmask(uint8_t bits);
82 void setPrevState(uint8_t col, uint8_t row, bool state);
83
84 unsigned long debounceTime = BUTTON_DEBOUNCE_TIME;
85 unsigned long prevRefresh = 0;
86 uint8_t prevStates[(NumCols * NumRows + 7) / 8];
87
90};
91
93
94#include "ButtonMatrix.ipp" // Template implementations
#define END_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
A class that reads the states of a button matrix.
ButtonMatrix(const PinList< NumRows > &rowPins, const PinList< NumCols > &colPins)
Construct a new ButtonMatrix object.
void setPrevState(uint8_t col, uint8_t row, bool state)
void setDebounceTime(unsigned long debounceTime)
Configure the debounce time interval.
bool getPrevState(uint8_t col, uint8_t row)
Get the state of the button in the given column and row.
static uint8_t bitsToIndex(uint8_t bits)
unsigned long getDebounceTime() const
Get the debounce time.
static uint8_t bitsToBitmask(uint8_t bits)
void onButtonChanged(uint8_t row, uint8_t col, bool state)=delete
The callback function that is called whenever a button changes state.
void begin()
Initialize (enable internal pull-up resistors on column pins).
static uint8_t positionToBits(uint8_t col, uint8_t row)
void update()
Scan the matrix, read all button states, and call the onButtonChanged callback.
const PinList< NumRows > rowPins
const PinList< NumCols > colPins
constexpr unsigned long BUTTON_DEBOUNCE_TIME
The debounce time for momentary push buttons in milliseconds.
An array wrapper for easy copying, comparing, and iterating.
Definition Array.hpp:32