Button Programming

Is there a way to program buttons on the vex controller start and stop functions by taping on the button in stead of holding down on the button?

Typically, this type of behavior would be done through the use of flags; boolean variables that are set to either a true or false value depending on if you want the function to be run or not. For example:


bool testFlag = false;

task main()
{
	while(true)
	{
		//If the button is pressed and the flag is false
		if(vexRT[Btn5D] == 1 && testFlag == false)
		{
			//Set the flag to true
			testFlag = true;
			//Idle loop until the button is released
			while(vexRT[Btn5D] == 1)
			{
				//Sleep to eliminate debounce
				sleep(10);	
			}
		}

		//Else, if the button is pressed and the flag is true
		else if(vexRT[Btn5D] == 1 && testFlag == true)
		{
			//Set the flag to false
			testFlag = false;
			//Idle loop until the button is released
			while(vexRT[Btn5D] == 1)
			{
				//Switch to eliminate debounce
				sleep(10);		
			}
		}

		//Later, check to see if the flag is true or false
		//and run a function if it is true
		if(testFlag == true)
		{
			//Function to run
		}
	}
}

I made the flag a global variable as you typically will want to ‘reset’ the flag back to false at the end of your function (so it only runs once, and requires another button press before running again). As always, there are improvements that can be made to this code, but it should serve as a good baseline introduction for what you would like to do.