Bumper sensor Help

so we have a bumper sensor on our robot and we want a specific motor to stop moving when it hits the bumper sensor. I will put my code below but it is not working.

Any help would be helpful. Thanks for your time!

void usercontrol(void) {

while (1) {
  if(Controller1.ButtonY.pressing()) {
          Tilter.spin(vex::directionType::fwd, TilterMotorPCT, vex::velocityUnits::pct);
      }
      else if(Controller1.ButtonX.pressing()) {
          Tilter.spin(vex::directionType::rev, TilterMotorPCT, vex::velocityUnits::pct);
      }
      else {
          Tilter.stop(vex::brakeType::coast);
      }
       if (BumperH.pressing()) {
        Brain.Screen.printAt(1, 20, "bumper pressed");
        Tilter.stop(vex::brakeType::coast);
        
    } else {
        Brain.Screen.printAt(1, 20, "bumper released");
    }
  }

You need to combine your two if else statements
If (bumper pressing){
Tilter stop;
}
Else{
Other commends for your tilter
}

2 Likes