Running multiple if/else statements

I am having some trouble running code with multiple if/else statements. when I try to move the intake the motors won’t move.

if(Controller1.ButtonR2.pressing()){
 bottomIntake.setVelocity(100,percent);

  bottomIntake.spin(forward);
}

else{
  bottomIntake.stop();

}
if(Controller1.ButtonR1.pressing()){
  MiddleIntake.setVelocity(100,percent);
  TankIntake.setVelocity(100,percent);
  TankIntake.spin(forward);
  MiddleIntake.spin(forward);

}
 else{
   MiddleIntake.stop();
   TankIntake.stop();
 }
 if(Controller1.ButtonL2.pressing()){
   bottomIntake.setVelocity(100,percent);
   bottomIntake.spin(reverse);
   
 }
 else{
   bottomIntake.stop();
  
 }   
 
  if(Controller1.ButtonL1.pressing()){
  MiddleIntake.setVelocity(100,percent);
  TankIntake.setVelocity(100,percent);
  TankIntake.spin(reverse);
  MiddleIntake.spin(reverse);

}
 else{
   MiddleIntake.stop();
   TankIntake.stop();

All code relating to a single motor should be in just one if, else if, else statement. What is happening so if u tell ur middle intake to go froward, it then goes down the list and sees that L1 isnt pressing, so it stops the motors base don that statement. Code should be

if(Controller1.ButtonR1.pressing()){
MiddleIntake.setVelocity(100,percent);
TankIntake.setVelocity(100,percent);
TankIntake.spin(forward);
MiddleIntake.spin(forward);

}

else if((Controller1.ButtonR1.pressing()){
iddleIntake.setVelocity(100,percent);
TankIntake.setVelocity(100,percent);
TankIntake.spin(reverse);
MiddleIntake.spin(reverse);

}

else {
MiddleIntake.stop();
TankIntake.stop();
}

3 Likes

i tried your code and the forward works fine but when i try to go reverse the motors make a kind of pulse. Any ideas why?

Yes, I accidentally messed up and made both commands work with the same button: the correct code would be:

if(Controller1.ButtonR1.pressing()){
MiddleIntake.setVelocity(100,percent);
TankIntake.setVelocity(100,percent);
TankIntake.spin(forward);
MiddleIntake.spin(forward);

}

else if((Controller1.ButtonL1.pressing()){
MiddleIntake.setVelocity(100,percent);
TankIntake.setVelocity(100,percent);
TankIntake.spin(reverse);
MiddleIntake.spin(reverse);

}

else {
MiddleIntake.stop();
TankIntake.stop();
}

3 Likes

i edited that part and it is still pulsing

if(Controller1.ButtonR1.pressing()){
MiddleIntake.setVelocity(100,percent);
TankIntake.setVelocity(100,percent);
TankIntake.spin(forward);
MiddleIntake.spin(forward);
}
else if((Controller1.ButtonL1.pressing())){
MiddleIntake.setVelocity(100,percent);
TankIntake.setVelocity(100,percent);
TankIntake.spin(reverse);
MiddleIntake.spin(reverse);
}
else {
MiddleIntake.stop();
TankIntake.stop();
}
if(Controller1.ButtonR2.pressing()){
bottomIntake.setVelocity(100,percent);
bottomIntake.spin(forward);
}
else if((Controller1.ButtonL2.pressing())){
bottomIntake.setVelocity(100,percent);
bottomIntake.spin(reverse);
}
else {
bottomIntake.stop();
}

I have no idea, try setting velocity to -100 and direction to forward

1 Like

it worked thank you so much!