Is there a motor toggling system for controls?

Hello there person reading this.

Right now I am currently working on my frustrating-to-work-on robot and I wanted to make a toggle system in which you press a button once and the intake rollers move at an optional speed in a certain direction and you press another button (or the same button if possible) and it goes the other direction with another optional speed. I would also like to know if there is a way to cancel the toggle.

I am using ROBOTC. (yes i know it shows in the category)

Can somebody help me with this?

I have two motors for each side of the intake rollers, and they are hooked onto port 9 and 7.

If this is basically not possible, please tell me. I already have an idea in mind for what I can do.

Thank you.

you can adapt the logic of this to robotc and then each button press sets the motors to do something different:

2 Likes

As I was writing a reply about a problem, I realized something that was simple yet fixed the problem. I finally got the toggle system working! I think I can duplicate the code and set the direction to go differently when another button is pressed now. Thanks!

…and for those wonder how my code looks, here it is from a testing file:

task main()
{
bool last = false;

while(true)
	   {
   if(vexRT[BUTTON] == 1)
     {
      motor[PORT] = -127;
      motor[PORT] = 127;
      last = true;
      }
      else if(vexRT[BUTTON] == 1)
      {
      motor[PORT] = 0;
      motor[PORT] = 0;
      last = false;
      }
}
}

Edit: No I can’t copy and paste xddd
Edit 2: I got the main functions down I just had to remove some code. Now I need to be able to stop the motors from running.
Edit 3: It is completed.

Here is specifically my code:

 if(vexRT[Btn8D] == 1)
 {
  motor[port9] = -127;
  motor[port7] = 127;
  last = true;
  }
  else if(vexRT[Btn8U] == 1)
  {
  motor[port9] = 127;
  motor[port7] = -127;
  last = true;
  }
  	else if(vexRT[Btn8L] == 1)
  {
  motor[port9] = 0;
  motor[port7] = 0;
  last = false;
  }
1 Like