Skip to content

Instantly share code, notes, and snippets.

@rajkundu
Created April 26, 2018 03:05
Show Gist options
  • Save rajkundu/83ca067b850fbdc84f4c6a0c688dd5ed to your computer and use it in GitHub Desktop.
Save rajkundu/83ca067b850fbdc84f4c6a0c688dd5ed to your computer and use it in GitHub Desktop.
Example of code to toggle between two modes on a robot in RobotC
bool myToggleEnabled = true;
//-------------------- Code for toggling between modes --------------------//
//Let's say you must press all 4 buttons on the back of the controller to switch modes.
if((vexRT[Btn5U] == 1)&&(vexRT[Btn5D] == 1)&&(vexRT[Btn6U] == 1)&&(vexRT[Btn6D] == 1))
{
while((vexRT[Btn5U] == 1)&&(vexRT[Btn5D] == 1)&&(vexRT[Btn6U] == 1)&&(vexRT[Btn6D] == 1))
{
//Wait for toggle buttons to be released
//Otherwise, it toggles really fast, which I indeed learned that the hard way
wait1Msec(10);
}
myToggleEnabled = !myToggleEnabled;
}
//-------------------- Code for actually moving the claw --------------------//
if(myToggleEnabled)
{
//Code for Mode 1, when the toggle is enabled (e.g. auto claw mode)
if(vexRT[Btn5U] == 1)
{
motor[myClaw] = -80;
wait1Msec(250);
motor[myClaw] = 0;
}
//Button 6 Up for closing claw
else if(vexRT[Btn6U] == 1)
{
motor[myClaw] = 80;
wait1Msec(250);
//Keep a tiny bit of closing force on the cone (or just setting to 0 also works)
motor[myClaw] = 16;
}
}
else
{
//Code for Mode 2, when the toggle is disabled (e.g. manual claw mode)
//Button 5 Up for opening claw
if(vexRT[Btn5U] == 1)
{
motor[myClaw] = -80;
}
//Button 6 Up for closing claw
else if(vexRT[Btn6U] == 1)
{
motor[myClaw] = 80;
}
//If neither button is pressed
else
{
//Keep a tiny bit of closing force on the cone (or just setting to 0 also works)
motor[myClaw] = 16;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment