I am trying to create a object for a LED matrix which could have a varying size throughout a program's runtime. To do this I am trying to dynamically create an object from the OctoWS2811 library and define it's size within the constructor of a display class. How would I do this properly? Is this possible? Thank you
Here is the normal way an OctoWS2811 object is created:
const int ledsPerPin = 120 * (32 / 8);
DMAMEM int displayMemory[ledsPerPin * 6];
int drawingMemory[ledsPerPin * 6];
const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 leds(ledsPerPin, displayMemory, drawingMemory, config);
And here is an example of what I am trying to do:
#include <Arduino.h>
#include <OctoWS2811.h>
class Display
{
OctoWS2811 *leds; // Dynamically allocated
DMAMEM int *displayMemory;
int *drawingMemory;
const int config = WS2811_GRB | WS2811_800kHz;
int width, height;
public:
Display(int w, int h);
void Draw();
};
Display::Display(int w, int h)
{
width = w;
height = h; //Must be multiple of 8
int ledsPerPin = (height / 8) * width;
displayMemory = new DMAMEM int[ledsPerPin * 6];
drawingMemory = new int[ledsPerPin * 6];
OctoWS2811 temp(ledsPerPin, displayMemory, drawingMemory, config);
*leds = temp; //How do I do this properly?
}
void Display::Draw() {
// Draw stuff with the object
leds.setPixel(56, 0xFF0000);
}
void setup()
{
Display Test(120, 32);
// put your setup code here, to run once:
}
void loop()
{
// put your main code here, to run repeatedly:
}