You've got lots of options we can help you with. Time can be based on counting the number of loops within the 18.5ms loop area or based on a hardware timer.
You can learn about state machines - what we typically use in cases like these.
Code:
static int counter=0; //keep track of loops to use as a crude timer - static keeps it around from call to call and isn't necessary if you never leave the subroutine.
static int autostate=1; //keep track of what step we're supposed to be doing
switch (autostate)
{
case 1: // Drive forward
pwm02 = 100;
pwm03 = 155; //motor is reversed
if (counter>54) //1 second (1 sec divided by 18.5ms = 54 loops per second)
{
autostate = 2; // move on to the next step
counter = 0; // reset our timer for the next step
}
case 2: // Turnaround
pwm02 = 100;
pwm03 = 100; //motor is reversed
if (counter>108) //2 seconds
{
autostate = 3;
counter = 0;
}
case 3: // Drive forward (returning now)
pwm02 = 100;
pwm03 = 155; //motor is reversed
if (counter>54) //1 second
{
autostate = 4;
counter = 0;
}
case 4: // Stop - What to do when everything else is done
default: // also what to do if an invalid autostate occurs
pwm02 = pwm03= 127; // Make sure the last thing you do is always stop
}
counter++;
You can also write your own WAIT subroutine to do what you want if you prefer to flow through one set of commands. There's an easy way to do this for Autonomous based on the User_Autonomous_Code structure and counting the way Foster suggested. It's not something you would use in Teleop where you want to respond to driver commands instantaneously.