I want to make a library from one of my sketches (DycoLed). Everything works fine by now, but now I have a problem.
DycoLed library, designed for USI inferface
// will be set in constucor (?)
const int LEDCOUNT = 3;
// custom array which holds the color information
// word array for the messages for the leds
// check if leds are already initialized
boolean isInit = 0;
At the moment I use a constant LEDCOUNT to set the size of my arrays and for the loops in my functions. When I change it, it works pretty good. But here comes the problem for the library.
The size of the arrays should be dynamic, therefore my lib should get the count of the used leds in the init method. But then it is already to late to change the size of the array.
example (not in my code):
int ledPin; // value can be changed at any time
int anyNumber; //not valid without values or size
A normal variable can be changed at any time, but the size of an arry must be set right at the declaration, not later. This fact makes it very difficult to set the size of the arrays in the .cpp or .h file for the lib, because I don't know the count of used leds at this time.
Is there any method (or workaround) to solve this problem?
I could imagine one. Generate an array of objects from my lib. But then there would be copies of all functions I use, and that would be a mess, too.
Correct me if i'm wrong