That looks good.
Yes, I was just showing an elaboration on what Foster told you. Instead of the Case statement you can use If statements like you did.
The only way the loop will take longer than 18.5ms is if the code you add takes more than 18.5ms to execute and slows everything down so you don't get to the "if (statusflag.NEW_SPI_DATA)" statement in time. That would take an intense time-consuming internal loop, not the sets and checks you're doing.
For a simple Wait just duplicate the structure you already recognize. You want to repeat all the work that routine does, so the system doesn't lockup while you wait.
I just dashed this off and haven't checked it, but this is the general idea using what you've already learned. You'd add something like this before User_Autonomous_Code.
Code:
void My_Wait(int milliseconds)
{
int elapsedtime=0; // in increments of 18.5ms
int elapsedcount=0; // in units of 18.5ms
while((elapsedtime < milliseconds) & autonomous_mode) // also quit if Auto mode happens to end
{
if (statusflag.NEW_SPI_DATA) /* 18.5ms loop area */
{
elapsedcount++;
elapsedtime = elapsedcount * 185 / 10; //the Vex PIC processor doesn't have floating point
Getdata(&rxdata); // tells us when Auto Mode is over
Putdata(&txdata); // Lets the master controller know we're alive and well
}
}
}
And then in User_Autonomous_Code you can do something like this:
pwm02 = 100;
pwm03 = 155;
My_Wait(5000);
pwm02 = 127;
pwm03 = 127;