Button Programming Help

Hi, we want to make a button perform a one-time task- to spin motor A for 6.3 seconds at 63. We set it to this:

	while (vexRT[Btn7R] == 1)
	{
		motor(RampA) = 63;
		wait1Msec(6000);
	
	}
	while (vexRT[Btn7L] == 1)
	{
		motor(RampA) = 0;
	}

However it doesn’t work. How do we set it to work so that when we hit motor 7R it runs at 63 for 6 seconds, then shuts off without having the press 7L? Thank you.

In your first while loop, you didn’t give a way for the motor power to be set back to 0 after it was set to 63. What you want to do is when 7R is pressed you want to set the motor to 63, wait for 6.3 seconds, and then set it back to 0. Your code should look something like this:


while(vexRT[Btn7R] == 1)
{
    motor[RampA] = 63; //set to 63
    wait1Msec(6300); //6300 msec is 6.3 seconds
    motor[RampA] = 0; //after waiting 6.3 seconds, set back to 0
}
while(1){
  If(vexRT[Btn7R){
    motor[RampA]=63;
    wait1ms(6000);
    motor[RampA]=0;
  }
}

This setup runs the motor for 6 seconds and then stops it. Remember when it comes to controlling motors that telling them to stop is an action.

Written on my phone so the spacing might not be perfect.