function up the loop and all you need is the pattern# enum parameter and its good to go.
this has a small fragility, if you go out of bounds on a pattern you will mess up or read from the next pattern. But if you can handle iteration over a fixed length buffer, it is one simple way to solve the problem.
You either put them in a 2-index array pattern_StepState[i][j] - as @handy andy advised you right at the start - and loop over the i index or i and j indices as you wish ...
... or you loop over a 1-index array pattern_StepState[k] with k going from 0 to 255.
which approach do you want to use, and I will try to show you.
you should mask that 16 as a constant. Magic numbers cause problems when you need to update / modify/ grow the code later.
from the looks of it you have a fair bit of code, making me recommend the vector of pointers approach at the end of my last post, but Im ok with anything.
that might look like this:
//don't need any if pattern number things.
for(i = 0; i < magic; i++)
if(vecpattern[patternnumber][i] == 1) //vecpattern [n] is a pointer that is the array start location for PatternB or whatever, so you can dereference it exactly as if it were PatternB here
stepState[i] = 1;
you can get funky and have a class that contains pointers, one for stepstate and one for button, or you can have 2 decoupled vectors .. I dunno, its YOUR data structure. It looks to me like you would want to couple them, but ?? If you were doing it from scratch you wouldn't probably do it this way at all, this is a retro-fit that is simple. Just be aware of that for next time ... this is a band-aid.
if you do it with the class its just 1 more layer
vecpattern[patternnumber][buttonptr][i] and vecpattern[patternnumber][stepptr][i]
ok, so wherever you define patternA ...
uint8_t* buttonptr; //or is this bool?
vector <patternwrapper> somename(magicvaluefor16);
somename.stepptr = patternA_StepState;
somename.buttonptr = patternA_buttonFlag;
... dothisfor all of them...
then use it like above:
Does this make sense or do you need more?
/shrug I am not sure what you have at this point, buy my understanding is it worked but you had all the variables loose rather than contained nicely? Any of several of the above code can build a structure that works but most involve rewrites. What I just gave you patches in on top of what's there to provide a cleaner access point, that is ALL it really does. You can still use patternA etc variables where you need to, if you need to. Its all the same memory and which access point you use is just whatever is simple in the current code block...
a total re-write gets rid of the pointers of course. Then you don't have the risks of going out of bounds on anything. But that is a lot of work .. up to you if you think a do-over is needed.
I patched into what you had. This leads to a more invasive re-write.
If you are going to do that, you may as well make the struct members vectors to clean it up a bit. And use bool type, not uint8, for true/false values.
and I still recommend that enum for patternA etc names, to index into allthepatterns (or whatever you want to name it). If you find that useful anywhere ? looks like
allthepatterns[patternA].buttonFlag[i] //if this is meaningful. Here, the enum is a more natural 0,1,2,3.... values, not the skip list in the original idea, and if you add a max_value to the end of it, that can BE your (value of 16) above number and it will grow for you without any work if you insert a patternX value someday...