|
Re: quick question: TIMERS
Your code is begging to become a state machine. It is a codeing techinque that uses a switch statement and where each case is an independant state. This works well because of the 26.3 ms looping process. The benefit of state machines is that it can be written so that some states are re-entrant where they look for some event like time or distance to trigger the program into the next state.
switch (state) {
case 1 :
// start motors
t = time + SomeDiration
break;
case 2 :
if (time < t) // This is re-entrant.
state = 2;
else
state = 3;
break;
case 3 :
// stop motors and start next manuever...
...
Get the picture? It's not hard. It does require some thought. But this is how most very complex programs start out. There are other ways of doing this with pointers and trillions of function - but this is just so simple and readable.
If you are at the Great Lakes Competition look me up and I'll show you more.
|