Vex Coding Studio help. Problem with assigning buttons to the same motor.

  1. 2 weeks ago
    Edited 2 weeks ago by StandingFuture

    We are trying to make a motor spin forward with one button and backward with another button. It is causing the motor to glitch out and not work. Here is the code.

    This doesn't work together:
    CapLifter.spin(vex::directionType::fwd, Controller1.ButtonL1.pressing()*100, vex::velocityUnits::pct); CapLifter.spin(vex::directionType::fwd, -Controller1.ButtonL2.pressing()*100, vex::velocityUnits::pct);

    This works by itself:
    CapLifter.spin(vex::directionType::fwd, Controller1.ButtonL1.pressing()*100, vex::velocityUnits::pct);

    Example of what @Kselva20 Was Saying

    if(Controller1.ButtonL1.pressing()){
        CapLifter.spin(vex::directionType::fwd, 100,  vex::velocityUnits::pct);
    }
    else if( Controller1.ButtonL2.pressing()){
        CapLifter.spin(vex::directionType::rev, 100,  vex::velocityUnits::pct);
    }
    else {
        CaprLifter.stop(brakeType::brake);
    }

    The Stop command may be different in VCS as I personally use Robot Mesh

  2. Kselva20

    Jan 4 5249Z

    Try this:

    if(Controller1.ButtonL1.pressing()){
        CapLifter.spin(vex::directionType::fwd, 100,  vex::velocityUnits::pct);
    }
    else if( Controller1.ButtonL2.pressing()){
        CapLifter.spin(vex::directionType::rev, 100,  vex::velocityUnits::pct);
    }
  3. After trying that, the motors don't stop spinning upon releasing the buttons like in the normal command. I'm trying to think of ways to implement it without needing to add multiple else-if statements that make the code messy.

  4. Kselva20

    Jan 4 5249Z

    Have an else statement having the motors stop. This the way I have been doing it for 3 years, and I have not seen it as messy. This is probably the best way to do it.

  5. G.A.T Wrenches

    Jan 4 Answer Groton 9050 C
    Edited 2 weeks ago by G.A.T Wrenches

    Example of what @Kselva20 Was Saying

    if(Controller1.ButtonL1.pressing()){
        CapLifter.spin(vex::directionType::fwd, 100,  vex::velocityUnits::pct);
    }
    else if( Controller1.ButtonL2.pressing()){
        CapLifter.spin(vex::directionType::rev, 100,  vex::velocityUnits::pct);
    }
    else {
        CaprLifter.stop(brakeType::brake);
    }

    The Stop command may be different in VCS as I personally use Robot Mesh

  6. Do the same thing as kselva20 suggested but just use two while loops.

    while(the button is pressed)
    {
    do the stuff;
    }
    while(the other button is pressed)
    {
    do the other stuff;
    }

  7. @rakibsta That will block the thread while the button is held. This is generally undesirable.

 

or Sign Up to reply!