What I want is to easily configure the following input so the pins are enabled and disabled for the given time and repetitions. So for example this would enable pins 18, 19 and 20 for 2 seconds then disable them and enable 17 and 19 for 1 second. This would happen 10 times and the the next repetition would start... 3 times pin 16 and 18 for 1 second... etc.
Input data
repetitions | duration | pins
10 | |
| 2000 | 20,18,19
| 1000 | 17,19
3 | |
| 1000 | 16,18
....and a lot more.
I thought to create classes and so I would be able to set the data and handle the funcionality easily.
Pseudo code
class LedzItem{
array int[];
int duration;
logics(){...}
void add(){}
}
class LedzGroup{
array LedzItem[];
int repetitions;
logics(){...}
LedzItem add(){}
}
class Ledz{
array LedzGroup[];
logics(){...}
LedzGroup add(){}
}
void setup(){
Ledz ledz = Ledz();
LedzGroup ledzGroup = ledz.Add(10);
LedzItem ledzItem = ledzGroup.add(2000);
ledzItem.add(20);
ledzItem.add(18);
}
I have working code (Ledz.ino on github) but it takes way to much memory because of the predefined array sizes.
To fix the array problem I tried working with a dynamic array like in this answer but then my program crashes when I add two groups. And when I add only one group I get some wrong values, so I guess pointer errors?(ledz_dynamic attempt on github)
So basically my question is: Is this a good way to process the input and accomplish what I want?
I don't want to write the input completely in for loops etc. I thought to make it easier to create classes which handle the for loops. That way I could more easily could insert the input data.