Issue with User Control Motors

I want to be able to have motors spinning while a button is being held and when the buttons is not being pressed the motors to not be doing anything. For some reason in this code the first part where I want to have the motor spin in the reverse direction doesn’t work. Can someone see an issue that I’m not seeing? Also this is going in my usercontrol while loop.

if(Controller1.ButtonX.pressing())
{
  liftLeft.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
  liftRight.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
}
else {
  liftLeft.spin(vex::directionType::rev, 0, vex::velocityUnits::pct);
  liftRight.spin(vex::directionType::rev, 0, vex::velocityUnits::pct);
}

if(Controller1.ButtonY.pressing())
{
  liftLeft.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
  liftRight.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}
else {
  liftLeft.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
  liftRight.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
}

I think your problem is that you have 2 separate if statements. So, the first if statement (The one checking the X button) executes and makes your motors run in the reverse direction. However, immediately after, the second if statement executes, and since Y isn’t pressed, the motors are told not to run.

To fix this, use elseif to make a single if-elseif-else chain, like below:

if(Controller1.ButtonX.pressing())
{
  liftLeft.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
  liftRight.spin(vex::directionType::rev, 100, vex::velocityUnits::pct);
}
else if(Controller1.ButtonY.pressing())
{
  liftLeft.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
  liftRight.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}
else {
  liftLeft.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
  liftRight.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
}
3 Likes

Thanks so much, it makes sense now that I’m seeing it. I’ll let you know tomorrow if it works.