There are a bunch of questions like this here, I can't quite fine the right one to nail this - am hoping for a clearer answer (eg. Array of pointers to arrays is close, I just can't make it work with the typedef).
This code defines a set of animation sequences for a set of LEDs. The value(s) to be output are chosen based on the sequence, model of hardware and stage in the sequence. I am tempted to repeat the for loops for each sequence but I'll probably use this again and might learn something here too.
Based on printing the values, I don't get what I expect from *(sequences[mode])[model][prevstage][ix]. What am I missing?
void sequence(unsigned char reset, t_mode mode, unsigned char delaydiv4)
{
typedef signed char seq_t[2][8][10];
const seq_t centreSequence = {
{
{ZERO_LEFT_2, ZERO_RIGHT_2, -1},
.
{-1},
},
{
{ONE_LEFT_2, ONE_RIGHT_2, -1},
.
{-1},
},
};
const seq_t leftSequence = {
{
{ZERO_RIGHT_2, -1},
.
{ZERO_LEFT_TOP, ZERO_LEFT_BOT, -1},
},
{
{ONE_RIGHT_2, -1},
.
{ONE_LEFT_TOP, ONE_LEFT_BOT, -1},
},
};
const seq_t rightSequence = {
{
{ZERO_RIGHT_2, -1},
.
.
{ZERO_LEFT_TOP, ZERO_LEFT_BOT, -1},
},
{
{ONE_RIGHT_2, -1},
.
.
{ONE_LEFT_TOP, ONE_LEFT_BOT, -1},
},
};
const seq_t* sequences[] = {&leftSequence, &rightSequence, ¢reSequence};
static unsigned char stage;
static unsigned char prevstage;
const unsigned char model = 0;
if (reset != 0)
{
stage = 1;
prevstage = 0;
}
for (unsigned ix=0; sequences[mode][model][prevstage][ix] != -1; ++ix)
{
digitalWrite(*(sequences[mode])[model][prevstage][ix], 0);
}