The code as-is works. It cycles through letters displaying each one on the board's (UNO R4 Wifi) led matrix. As soon as I uncomment any additional letter the board displays nothing and nothing is printed to Serial. I can comment out any of the active letters and uncomment any of the currently unused letters and it still works.
I'm new to Arduino and c++. Is there are limit to the of variables I can instantiate in the constructor or am I hitting a memory issue or something else?
What are some good options for debugging this and similar issues?
test.ino
#include "Arduino_LED_Matrix.h"
#include <String.h>
#include <cstddef>
#include <Arduino.h>
#include "MatrixAlphabet.h"
ArduinoLEDMatrix matrix;
MatrixAlphabet alphabet;
byte frame[8][12] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
void setup() {
Serial.begin(9600);
matrix.begin();
}
int index = 0;
void loop() {
// index = index % 4;
Letter letterA = alphabet.getLetterTest(index);
Serial.print("Rows:");
Serial.print(letterA.getRows());
Serial.print("\tCols:");
Serial.print(letterA.getCols());
Serial.println();
for(int row = 0; row < 5; row++) {
for(int col = 0; col < 3; col++) {
frame[row][col] = letterA.getByteArray()[row][col];
Serial.print(letterA.getByteArray()[row][col]);
Serial.print(",");
}
Serial.println();
}
Serial.println("----------------");
matrix.renderBitmap(frame, 8, 12);
delay(100);
index++;
}
MatrixAlphabet.h
#ifndef MATRIX_ALPHABET_H
#define MATRIX_ALPHABET_H
#include <iostream>
#include <vector>
#include <stdexcept>
#include <array>
#include "Letter.h"
class MatrixAlphabet {
public:
MatrixAlphabet();
Letter getLetterTest(int index);
private:
Letter A;
Letter B;
Letter C;
Letter D;
Letter E;
Letter F;
Letter G;
Letter H;
Letter I;
Letter J;
// Letter K;
// Letter L;
Letter M;
// Letter N;
// Letter O;
Letter P;
// Letter Q;
// Letter R;
// Letter S;
// Letter T;
// Letter U;
// Letter V;
// Letter W;
// Letter X;
// Letter Y;
// Letter Z;
std::vector<Letter> letters;
};
#endif
MatrixAlphabet.cpp
#include "MatrixAlphabet.h"
// Letter letters[] = {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z};
MatrixAlphabet::MatrixAlphabet() :
A(5, 3),
B(5, 3),
C(5, 3),
D(5, 3),
E(5, 3),
F(5, 3),
G(5, 3),
H(5, 3),
I(5, 3),
J(5, 3),
// K(5, 3),
// L(5, 3)
M(5, 3),
// N(5, 3)
// O(5, 3)
P(5, 3)
// Q(5, 3),
// R(5, 3),
// S(5, 3),
// T(5, 3),
// U(5, 3),
// V(5, 3),
// W(5, 3),
// X(5, 3),
// Y(5, 3),
// Z(5, 3)
{
A.fillFromByteArray({
{ 0, 1, 0 },
{ 1, 0, 1 },
{ 1, 1, 1 },
{ 1, 0, 1 },
{ 1, 0, 1 }
});
B.fillFromByteArray({
{ 1, 1, 0},
{ 1, 0, 1},
{ 1, 1, 0},
{ 1, 0, 1},
{ 1, 1, 0}
});
C.fillFromByteArray({
{ 0, 1, 0},
{ 1, 0, 1},
{ 1, 0, 0},
{ 1, 0, 1},
{ 0, 1, 0}
});
D.fillFromByteArray({
{ 1, 1, 0},
{ 1, 0, 1},
{ 1, 0, 1},
{ 1, 0, 1},
{ 1, 1, 0}
});
E.fillFromByteArray({
{ 1, 1, 1},
{ 1, 0, 0},
{ 1, 1, 1},
{ 1, 0, 0},
{ 1, 1, 1}
});
F.fillFromByteArray({
{ 1, 1, 1},
{ 1, 0, 0},
{ 1, 1, 1},
{ 1, 0, 0},
{ 1, 0, 0}
});
G.fillFromByteArray({
{ 1, 1, 1},
{ 1, 0, 0},
{ 1, 0, 1},
{ 1, 0, 1},
{ 1, 1, 1}
});
H.fillFromByteArray({
{ 1, 0, 1},
{ 1, 0, 1},
{ 1, 1, 1},
{ 1, 0, 1},
{ 1, 0, 1}
});
I.fillFromByteArray({
{ 1, 1, 1},
{ 0, 1, 0},
{ 0, 1, 0},
{ 0, 1, 0},
{ 1, 1, 1}
});
J.fillFromByteArray({
{ 1, 1, 1},
{ 0, 1, 0},
{ 0, 0, 1},
{ 1, 0, 1},
{ 0, 1, 0}
});
// K.fillFromByteArray({
// { 1, 0, 0},
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 1, 0},
// { 1, 0, 1}
// });
// L.fillFromByteArray({
// { 1, 0, 0},
// { 1, 0, 0},
// { 1, 0, 0},
// { 1, 0, 0},
// { 1, 1, 1}
// });
M.fillFromByteArray({
{ 1, 0, 1},
{ 1, 1, 1},
{ 1, 0, 1},
{ 1, 0, 1},
{ 1, 0, 1}
});
// N.fillFromByteArray({
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 1, 1},
// { 1, 0, 1},
// { 1, 0, 1}
// });
// O.fillFromByteArray({
// { 1, 1, 1},
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 1, 1}
// });
P.fillFromByteArray({
{ 1, 1, 0},
{ 1, 0, 1},
{ 1, 1, 0},
{ 1, 0, 0},
{ 1, 0, 0}
});
// Q.fillFromByteArray({
// { 1, 1, 1},
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 1, 1},
// { 1, 1, 1}
// });
// R.fillFromByteArray({
// { 1, 1, 0},
// { 1, 0, 1},
// { 1, 1, 0},
// { 1, 0, 1},
// { 1, 0, 1}
// });
// S.fillFromByteArray({
// { 0, 1, 1},
// { 1, 0, 0},
// { 0, 1, },
// { 0, 0, 1},
// { 1, 1, 0}
// });
// T.fillFromByteArray({
// { 1, 1, 1},
// { 0, 1, 0},
// { 0, 1, 0},
// { 0, 1, 0},
// { 0, 1, 0}
// });
// U.fillFromByteArray({
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 1, 1}
// });
// V.fillFromByteArray({
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 0, 1},
// { 0, 1, 0}
// });
// W.fillFromByteArray({
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 0, 1},
// { 1, 1, 1},
// { 1, 0, 1}
// });
// X.fillFromByteArray({
// { 1, 0, 1},
// { 1, 0, 1},
// { 0, 1, 0},
// { 1, 0, 1},
// { 1, 0, 1}
// });
// Y.fillFromByteArray({
// { 1, 0, 1},
// { 1, 0, 1},
// { 0, 1, 0},
// { 0, 1, 0},
// { 0, 1, 0}
// });
// Z.fillFromByteArray({
// { 1, 1, 1},
// { 0, 0, 1},
// { 0, 1, 0},
// { 1, 0, 0},
// { 1, 1, 1}
// });
letters = {A,B,C,D,E,F,G,H,I,J,M};
}
Letter MatrixAlphabet::getLetterTest(int index) {
return letters[index % size(letters)];
}
Letter.h
#ifndef LETTER_H
#define LETTER_H
#include <iostream>
#include <vector>
#include <stdexcept>
#include <array>
class Letter {
public:
Letter(int rows, int cols);
void fillFromByteArray(const std::vector<std::vector<uint8_t>> byteArray);
std::vector<std::vector<uint8_t>> getByteArray();
int getRows();
int getCols();
private:
int rows;
int cols;
std::vector<std::vector<uint8_t>> letterArray;
};
#endif
Letter.cpp
#include "Letter.h"
Letter::Letter(int rows_, int columns_) {
rows = rows_;
cols = columns_;
letterArray = std::vector<std::vector<uint8_t>>(rows, std::vector<uint8_t>(cols, 0));
}
void Letter::fillFromByteArray(const std::vector<std::vector<uint8_t>> byteArray) {
for (size_t i = 0; i < rows; ++i) {
for (size_t j = 0; j < cols; ++j) {
letterArray[i][j] = byteArray[i][j];
}
}
}
std::vector<std::vector<uint8_t>> Letter::getByteArray() {
return letterArray;
}
int Letter::getRows() {
return rows;
}
int Letter::getCols() {
return cols;
}