I wonder if anyone can help, I have the following (minimal) code which is not updating the LED matrix on my Arduino R4. if compiled directly into the .ino file all goes well, but as a potential shared class it fails to update the Led Matrix.
C++ is not my first language so hopefully it is just something dumb that I am doing wrong, but any help greatly appreciated.
.ino File:
#include <Arduino_LED_Matrix.h>
#include "LedManager.h"
LedManager ledManager;
void setup() {
Serial.begin(115200);
while (!Serial);
}
void loop() {
ledManager.ProcessLedMatrix(millis());
}
LedManager.h
#ifndef __LedManager__H
#define __LedManager__H
#include <Arduino_LED_Matrix.h>
const int MaxLedRows = 8;
const int MaxLedColumns = 12;
const byte LedOn = 1;
const byte LedOff = 0;
class LedManager
{
private:
bool _isOn = false;
unsigned long _lastUpdate = 0;
ArduinoLEDMatrix *_matrix;
byte _ledFrame[MaxLedRows][MaxLedColumns];
public:
LedManager();
~LedManager();
void ProcessLedMatrix(unsigned long currMillis);
};
#endif
LedManager.cpp
#include "LedManager.h"
LedManager::LedManager()
{
_matrix = new ArduinoLEDMatrix();
_matrix->begin();
}
LedManager::~LedManager()
{
delete(_matrix);
}
void LedManager::ProcessLedMatrix(unsigned long currMillis)
{
if (currMillis > _lastUpdate)
{
_isOn = !_isOn;
_ledFrame[5][4] = _isOn ? LedOn : LedOff;
_matrix->renderBitmap(_ledFrame, 8, 12);
_lastUpdate = currMillis + 1000;
Serial.print("Is on: ");
Serial.println(_isOn);
}
}
All compiles without warning and errors it just doesn't update the LED matrix.