Hi Guys,
Need a little help with the following array situation.
I have 16 arrays from patternA through to patternP each with 16 elements:
uint8_t patternA[16];
uint8_t patternB[16];
uint8_t patternC[16];
..
..
..
uint8_t patternP[16];
What I'm trying to achieve is an 'Array' of 'arrays' of sorts.
So when I create a 'for' loop I can cycle through and retrieve each element in each pattern.
Please see my example code. Its an example of going through ONLY two patterns, however rather than writing 16 of them, I would like to create a loop.
This was the intial concept I thought of...
Then I thought and tried using a struct, however that didn't seem to work.
Any thoughts or help would be great
Need a little help with the following array situation.
I have 16 arrays from patternA through to patternP each with 16 elements:
uint8_t patternA[16];
uint8_t patternB[16];
uint8_t patternC[16];
..
..
..
uint8_t patternP[16];
What I'm trying to achieve is an 'Array' of 'arrays' of sorts.
So when I create a 'for' loop I can cycle through and retrieve each element in each pattern.
Please see my example code. Its an example of going through ONLY two patterns, however rather than writing 16 of them, I would like to create a loop.
Code:
void recallPattern() {
if (pattern == 1) {
clearPattern();
for (int i = 0; i < 16; i++) {
if (patternA_StepState[i] == 1) {
stepState[i] = 1;
}
if (patternA_buttonFlag[i] == true) {
buttonFlag[i] = true;
}
}
}
if (pattern == 2) {
clearPattern();
for (int i = 0; i < 16; i++) {
if (patternB_StepState[i] == 1) {
stepState[i] = 1;
}
if (patternB_buttonFlag[i] == true) {
buttonFlag[i] = true;
}
}
}
}
This was the intial concept I thought of...
Code:
uint8_t patternArray[16][16] =
{ {patternA_StepState[]} , {patternB_StepState[]} ,
{patternC_StepState[]} , {patternD_StepState[]} ,
{patternE_StepState[]} , {patternF_StepState[]} ,
{patternG_StepState[]} , {patternH_StepState[]} ,
{patternI_StepState[]} , {patternJ_StepState[]} ,
{patternK_StepState[]} , {patternL_StepState[]} ,
{patternM_StepState[]} , {patternN_StepState[]} ,
{patternO_StepState[]} , {patternP_StepState[]} ,
}
Then I thought and tried using a struct, however that didn't seem to work.
Code:
struct Pattern {
uint8_t buttonFlag[16];
uint8_t stepState[16];
};
Pattern patternArg[16];
void recallPattern() {
for (int i = 0; i < 16; i++) {
if (pattern == i) {
clearPattern();
if (patternArg[i].stepState[i] == 1) {
stepState[i] = 1;
}
if (patternArg[i].buttonFlag[i] == true) {
buttonFlag[i] = true;
}
}
}
}
Any thoughts or help would be great
Last edited: