I am trying to create a function that will allow the use of variable sized multi dimensional arrays, but I'm having trouble wrapping my head around why something isn't working.
I don't think I need to paste the entire code, as it is a lot of repeating declarations, but I have a series of 1 dimensional arrays that store the colors to change LEDs to.
const long PupilDownLeft[] PROGMEM =
{
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x00a2e8, 0x00a2e8, 0x00a2e8,
0x000000, 0x000000, 0x000000, 0x00a2e8, 0xed1c24, 0xed1c24,
0x000000, 0x000000, 0x000000, 0x00a2e8, 0xed1c24, 0xed1c24
}
These are stored as pointers in another array. These can be variable sizes, depending on the length of the animation.
const long* BlinkAnim[][3] PROGMEM =
{
{PupilCenter, PupilClosed, PupilCenter}, //RightEye
{PupilCenter, PupilClosed, PupilCenter}, //LeftEye
{RightEyeOpen, RightEyeClosed, RightEyeOpen},
{LeftEyeOpen, LeftEyeClosed, LeftEyeOpen},
{RightBrow, RightBrowDown, RightBrow},
{LeftBrow, LeftBrowDown, LeftBrow},
};
The function declaration is currently this, which works as is.
void animDisplay(int animLen, int delayTimer, const long* anim[][3])
And it's called like this in the loop();
animDisplay(3, 300, BlinkAnim);
The issue arises if I want to use an array of a different size. For example, I have an array that has 10 items in each row.
const long* RollAnim[][10]
It works if I change the 3 to a 10 in the function declaration, but I wanted to make it dynamic.
I have tried to assign the length of the array to a variable outside the function (int animSize), and modified the function to be
void animDisplay(int animLen, int delayTimer, const long* anim[][animSize])
But I get a couple errors when I try to do that.
Individual_Eye_Test:298:59: error: expected ',' or '...' before 'anim'
void animDisplay(int animLen, int delayTimer, const long* anim[][animSize]){
and
In function 'void loop()':
Individual_Eye_Test:292:30: error: cannot convert 'const long int* (*)[3]' to 'const long int*'
for argument '3' to 'void animDisplay(int, int, const long int*)'
animDisplay(3, 300, BlinkAnim);
The same error also happens if I try to use the animLen variable that I declare in the function.
Is there any way to do what I'm wanting to do? Or would I have to make a new animDispay function for each possible size of array?