Skip to content

Instantly share code, notes, and snippets.

@kuzux
Created December 23, 2021 12:59
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/80d8363b22bf2e22afbe6f504f18c36e to your computer and use it in GitHub Desktop.
Save kuzux/80d8363b22bf2e22afbe6f504f18c36e to your computer and use it in GitHub Desktop.
#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 an 8x8 array of pixels - over 16 milliseconds
// 0 indexed
// assumes the screen was just cleared
void display(int** screen) {
for(int i=0; i<8; i++) {
digitalWrite(_rows[i], LOW);
for(int j=0; j<8; j++) {
if(screen[i][j]) digitalWrite(_cols[i], HIGH);
else digitalWrite(_cols[i], LOW);
}
delay(2);
digitalWrite(_rows[i], HIGH);
}
}
void clear() {
for(int i=0; i<8; i++) {
digitalWrite(_rows[i], HIGH);
digitalWrite(_cols[i], HIGH);
}
}
};
// 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 };
int screen[8][8] = { { 0, 1, 0, 1, 0, 1, 0, 1 },
{ 1, 0, 1, 0, 1, 0, 1, 0 },
{ 0, 1, 0, 1, 0, 1, 0, 1 },
{ 1, 0, 1, 0, 1, 0, 1, 0 },
{ 0, 1, 0, 1, 0, 1, 0, 1 },
{ 1, 0, 1, 0, 1, 0, 1, 0 },
{ 0, 1, 0, 1, 0, 1, 0, 1 },
{ 1, 0, 1, 0, 1, 0, 1, 0 } };
LedMatrix matrix(rows, cols);
void setup() {
matrix.begin();
}
void loop() {
matrix.clear();
matrix.display(screen);
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment