Skip to content

Instantly share code, notes, and snippets.

@kuzux
Last active December 23, 2021 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuzux/bde2fcbe71eeaded47b9de3b4185fd55 to your computer and use it in GitHub Desktop.
Save kuzux/bde2fcbe71eeaded47b9de3b4185fd55 to your computer and use it in GitHub Desktop.
#ifndef LEDMATRIX_H
#define LEDMATRIX_H
#include "Arduino.h"
class LedMatrix {
int _rows[8];
int _cols[8];
public:
LedMatrix(int rows[], int cols[]) {
for(int i=0; i<8; i++) {
_rows[i] = rows[i];
_cols[i] = cols[i];
}
}
void begin() {
for(int i=0; i<8; i++) {
pinMode(_rows[i], OUTPUT);
pinMode(_cols[i], OUTPUT);
}
}
// displays a single (row, column) "pixel"
// 0 indexed
// assumes the screen was just cleared
void display(int row, int column) {
digitalWrite(_rows[row], LOW);
digitalWrite(_cols[column], HIGH);
for(int i=0; i<8; i++) {
if(i != column) digitalWrite(_cols[i], LOW);
}
}
void clear() {
for(int i=0; i<8; i++) {
digitalWrite(_rows[i], HIGH);
digitalWrite(_cols[i], HIGH);
}
}
};
#endif
// as connected on https://www.arduino.cc/en/Tutorial/BuiltInExamples/RowColumnScanning
int rows[] = { 2, 7, A5, 5, 13, A4, 12, A2 };
int cols[] = { 6, 11, 10, 3, A3, 4, 8, 9 };
LedMatrix matrix(rows, cols);
void setup() {
matrix.begin();
}
void loop() {
matrix.clear();
matrix.display(3, 5);
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment