Hey! I’m writing the usercontrol for my robot and my team has decided that we want to switch between two different speeds with the press of a button. Basically, command that maps the motor value to the joystick value will be divided by an integer “speed”, and when the up dpad button is pressed once, speed will be equal to 1. However, when the down dpad button is pressed once, the speed value will be set to 2, which results in the robot being half the speed. How would I code this without getting bugs (I keep getting something about not being able to declare a function correctly). Here’s the code written in RobotC that I think should work, but I haven’t tried it out yet. Thanks for the help as always!
#pragma config(Motor, port1, leftSideDrive, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port2, rightSideDrive, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
int speed = 1;
task normalSpeed()
{
speed = 1;
}
task slowSpeed()
{
speed = 2;
}
task main()
{
while(1==1)
{
motor[leftSideDrive] = vexRT[Ch3] / speed;
motor[rightSideDrive] = vexRT[Ch2] / speed;
if(vexRT[Btn7U] == 1)
{
stopTask(slowSpeed);
startTask(normalSpeed);
}
else if(vexRT[Btn7D] == 1)
{
stopTask(normalSpeed);
startTask(slowSpeed);
}
}
}