#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port1, leftmotor, tmotorVex393_HBridge, PIDControl, encoderPort, I2C_1)
#pragma config(Motor, port2, rightmotor, tmotorVex393_MC29, PIDControl, encoderPort, I2C_2)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task One()
{
slaveMotor(leftmotor, rightmotor);
motor[rightmotor] = 50;
wait(300);
}
task Two()
{
slaveMotor(leftmotor, rightmotor);
motor[rightmotor] = 50;
wait(300);
}
task Three()
{
slaveMotor(leftmotor, rightmotor);
motor[rightmotor] = 50;
wait(300);
}
task main()
{
int nTaskToStart = 0; // int 'nTaskToStart' is set to '2'
while(1==1)
{
switch(nTaskToStart)// test 'nTaskToStart' in the switch
{
case1: // if 'nTaskToStart' is '1':
startTask(One); // start task One
break; // break out of this switch statement and continue code after the '}'
case2: // if 'nTaskToStart' is '2':
startTask(Two); // start task Two
break; // break out of this switch statement and continue code after the '}'
default: // if 'nTaskToStart' is anything other than '1' or '2':
startTask(Three);
break;
}
}
}
My team was going to use a switch case to jump between using different autonomouses (autonomousi?) in our competition code, but we’ve had problems getting them to work properly. We’re using one of the simplest ways to use a switch that we can find, and yet it consistently returns the error ‘‘switch’ statement block must start with ‘case/default’ statement’. We’ve done some checking around we have no idea what we’re doing differently than people who have used it properly. Any ideas what we’re doing wrong? I’d imagine it’s probably something simple that we’re overlooking.
Thanks!