VEXcode Text

Can someone tell me if you can add multiple motors in one button? And paste their code if possible? Because our team is trying to do that, but when we do put two motors under one button, the remote controls (after we download the robot) switch and it is doing a totally different function, when we press a different button.

yes
if(Controller1.ButtonR1.pressing()) {
LA.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct); RA.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct);
}
else if(Controller1.ButtonR2.pressing()) {
LA.spin(vex::directionType::fwd, DownSpeedPCT, vex::velocityUnits::pct); RA.spin(vex::directionType::fwd, DownSpeedPCT, vex::velocityUnits::pct);
}
else {
LA.stop(vex::brakeType::hold); RA.stop(vex::brakeType::hold);
}

2 Likes

You could also motor group them in the motor and sensor setup section:
Example:

vex::motor_group arm (LA, RA)

if(Controller1.ButtonR1.pressing()) {
arm.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct);
}
else if(Controller1.ButtonR2.pressing()) {
arm.spin(vex::directionType::fwd, DownSpeedPCT, vex::velocityUnits::pct);
}
else {
arm.stop(vex::brakeType::hold);
}

3 Likes

But how would this exactly operate under one button for two motors? Do you program the same button in two different if, else/if, and else statements and then groups them up?

No. All you need is to program one if/else statement with the motor group name for the button. It would just run both motors simultaneously, as if there were 2 separate if/else statements there. Just remember to setup the motor group in robot-config.cpp and robot-config.h.
Hope this helps! PM me if you need anything else. :slight_smile:

2 Likes

This is very informative post by @jpearman with examples of doing motor groups:

2 Likes