How to write the Joystick code in Vex Coding studio

Hi, everyone.
I only know how to use L1, L2, R1, R2 Button to control the motor. But how to program other buttons, such as X Y A B and ↑↓→←. More importantly, how to program two joysticks, so that they can control the Robot’s movement. Thank you for your help!
The following code is what I accomplished.
int main() {
while(true){
//Raise the Arm Motor if the R1 ButtonR1 is pressed
if(Controller1.ButtonL1.pressing()){
Motor1.spin(directionType::fwd, 50, velocityUnits::pct);
Motor2.spin(directionType::fwd, 50, velocityUnits::pct);
}
else if(Controller1.ButtonL2.pressing()){
Motor1.spin(directionType::rev, 50, velocityUnits::pct);
Motor2.spin(directionType::rev, 50, velocityUnits::pct);
}

    else if(Controller1.ButtonR1.pressing()){
        Motor3.spin(directionType::fwd, 50, velocityUnits::pct);
        Motor4.spin(directionType::fwd, 50, velocityUnits::pct);
    }
       
    else if(Controller1.ButtonL2.pressing()){
        Motor3.spin(directionType::rev, 50, velocityUnits::pct);
        Motor4.spin(directionType::rev, 50, velocityUnits::pct);
    }    
    //Else stop the arm and hold its current position
    else{
        Motor1.stop(brakeType::hold);
        Motor2.stop(brakeType::hold);
        Motor3.stop(brakeType::hold);
        Motor4.stop(brakeType::hold);
    }
    }
}

If you are using VCS, take a look at the examples they provided

2 Likes

Just going to start off by saying don’t use VCS because it has been discontinued so switch to VEXcode or PROS. I personally use VEXcode because it is similar to VCS and I used it last season.

Anyways some joystick code for VCS and VEXcode is

motor.spin(directionType::fwd, controller.axis2.value(), velocityUnits::(pct or rpm));

this will make your motor spin at the position axis 2 on the joystick given that the furthest it can go is 100 pct or 200 rpm

2 Likes