34 lines
768 B
C++
34 lines
768 B
C++
#include "Matrix.h"
|
|
|
|
Matrix::Matrix(uint8_t* columns, uint8_t num_columns, bool inverted) {
|
|
this->active_pin = 255; // sentinel value, highest possible 8-bit number
|
|
this->inverted = inverted;
|
|
|
|
for (uint8_t i = 0; i < num_columns; i++) {
|
|
pinMode(columns[i], OUTPUT);
|
|
_disable(columns[i]);
|
|
}
|
|
}
|
|
|
|
void Matrix::Activate(uint8_t pin) {
|
|
if (pin == active_pin) return;
|
|
|
|
if (active_pin != 255) {
|
|
_disable(active_pin);
|
|
}
|
|
|
|
_enable(pin);
|
|
active_pin = pin;
|
|
delayMicroseconds(10); // allow ample time for signal to propagate
|
|
}
|
|
|
|
void Matrix::_enable(uint8_t pin) {
|
|
if (inverted) digitalWrite(pin, LOW);
|
|
else digitalWrite(pin, HIGH);
|
|
}
|
|
|
|
void Matrix::_disable(uint8_t pin) {
|
|
if (inverted) digitalWrite(pin, HIGH);
|
|
else digitalWrite(pin, LOW);
|
|
}
|