How do I program two motors to one button

I am trying to program two motors to one button. one button to make them go one way and one to make it go the other. (in the v5 system)

the program ;

while(true) {
if ( Controller1 . ButtonUp. pressing ( ) )
{
intakeM.spin( directionType: : fwd, armSpeedPCT, velocityUnits: : pct);
intakeM2.spin( directionType: : fwd, armSpeedPCT, velocityUnits: : pct);
}

    else if( Controller1.ButtonDown.pressing( ) ) 
    {
        intakeM.spin( directionType: : rev, armSpeedPCT, velocityUnits: : pct);
        intakeM2.spin( directionType: : rev, armSpeedPCT, velocityUnits: : pct);
    }

    else 
    {
        intakeM.stop( ) ;
        intakeM2.stop( ) ;
    }

you can use
the things in ~~ are where you put in your own things
vex::motor_group ~motorgroupname~ (~Motor~, ~Motor~);
and then
~motorgroupname~.spin(rev, armSpeedPCT, pct);

What is you problem? The code you post looks correct and should work. Is the program giving you an error message or is the code just not working as expected.

What @LAMMAZ said is an option you have for shortening you code is motor groups. They allow you to run multiple motors with one line of code, but is necessary.

Also to format your code properly you can do this…

```cpp
int yourCodeGoesHere;
```
The cpp tells it to highlight it as cpp code. It supports other languages too, and if left blank it will choose one for you.

1 Like

it’s only doing one motor not both

Does the brain recognize both motors?
Are the ports correct in the code?

I don’t think the problem is with the part of your code you posted.

1 Like

Does the brain recognize both motors? yes
Are the ports correct in the code? am not sure

and even with the motor group it only one side works

Try removing the extra spaces in between and around semicolons

Motor.spin(directionType: : forward) -> Motor.spin(directionType::forward)

1 Like

The problem may be the motor, wire or port on the brain, instead of a software bug. Plug the non running motor in, if the light turn in then it is probably code, if it remains off, then it is a faulty motor (to test plug wire into another motor and check for the red light), a faulty wire, or fried brain port.(Simply change the assigned port to test)

2 Likes

tried all of that but all is good but still does not work

still not working :sweat_smile: :sweat_smile:

Could you upload a screenshot of the code?

pt1prog

1 Like

are you using the competition template?
i suggest using that if your new.

What does the error say? I’m guessing it’s probably because there’s too much/not enough curly brackets

1 Like

the function is not allowed

Could you also upload a screenshot of the error?

The code for driver control should go into the driver control loop

1 Like

pt2prog

Screenshot_20191210-164915~2
The code in the red bracket should be in the driver control loop.

This is what should be in your int main loop if you are using competition template:

int main() {
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);
  pre_auton();
  while (true) {
    wait(100, msec);
  }
}
1 Like

the
pre_auton();
while (true) {
wait(100, msec);
is there just lower down out of the photo

void usercontrol(void) {

Lmotor.spin(directionType::fwd, ( Controller1.Axis2.position(), pct);
Rmotor.spin(directionType::fwd, ( Controller1.Axis3.position(), pct);
LmotorB.spin(directionType::fwd, ( Controller1.Axis2.position(), pct);
RmotorB.spin(directionType::fwd, ( Controller1.Axis3.position(), pct);

while (1) {

if (Controller1.ButtonUp.pressing()) {

MIntakeM.spin( directionType::fwd, armSpeedPCT, pct);

} else if {

MIntakeM.spin( directionType::fwd, armSpeedPCT, pct);

} else {

MIntakeM.stop();

}