Simple, until you really need to do something while the display is running (which is pretty common!). The implementation of nested logic in round robin multitasking is classically difficult. But it can be done. Here are some ideas:
Here is how you implement a for loop using a state machine:
for(i=3; i<6; i++) {<somecode>}
decomposes as the sequence
i=3;
while (i<6) {
<somecode>
i++;
}
For the state machine you would do something like
if (state == INITIALIZE) {
i=3;
state = RUN;
}
else if (state == RUN and i<6) {
<somecode>
i++;
}
else {
state = IDLE;
}
To activate it, you just assert:
state = INITIALIZE;
Or, you can use a switch case statement:
switch (state) {
case:INITIALIZE
i=3;
state = RUN;
break;
case:RUN
if (i<6) {
<somecode>
i++;
}
else
{
state = IDLE;
}
break;
case: IDLE
break;
}
Nice wiring job, by the way!