How to program button pressed in VEXcode Pro V5

Hello. I hope everyone’s season of Vex Robotics is going well. We are currently working on a new robot and the chassis is too fast for some conditions when competing in Tipping Point. I am wanting to make a program that changes the chassis speed between 50% and 100%. I want to change between the preset speeds when I press button B on Controller 1. My understanding of this is that I need to use a bool (Boolean) as a two-value variable. Then I would set one of the bool values to one of the chassis speeds and vice versa. For example, when bool == 1, chassis =100%. When bool == 0, 50% = chassis speed. A resource I have been using is W3SCHOOLS. I provided the link below. I also provided an image of our code as a visual guide. When I ran the code that I have written, the robot only drives at 50% and is unable to switch back and forth between the two speed settings. If anyone has any ideas on how to fix this issue and is willing to share the knowledge, that would be greatly appreciated. Good luck in Tipping Point

Code JPEG:

W3SCHOOL Website:
(C++ Booleans) W3SCHOOLS.

2 Likes

try using this instead of the other button press line.

if (Controller1.ButtonB.pressed()) {
Chassis_Speed();
}

This should work but I am not familiar with vexcode specifically. Let me know how it goes.

We use this to toggle drive speed if this is what you’re talking about:

    //Driving
    if(ParkingControl == 0) {
      
      //Coast if wheels are not in use
      if(Controller.Axis3.value() == 0 && Controller.Axis2.value() == 0) {

        UnlockWheels();

      //Tank-style driving
      } else {

        StartDriving(Controller.Axis3.value(),Controller.Axis2.value());
      }
    }

    //Parking control
    if(ParkingControl == 1) {
      
      //Brake if wheels are not in use
      if(Controller.Axis3.value() == 0 && Controller.Axis2.value() == 0) {

        LockWheels();

      //Tank-style driving
      } else {

        StartDriving(0.5 * Controller.Axis3.value(),0.5 * Controller.Axis2.value());
      }
    }

    //Parking control (toggle)
    if(Controller.ButtonRight.pressing() == 1) {

      StopAll();

      //On
      if(ParkingControl == 0) {

        while(Controller.ButtonRight.pressing() == 1) {

          ParkingControl = 1;
        }
        
        Latch.close();
        Controller.rumble("-");
      }

      //Off
      if(ParkingControl == 1) {

        while(Controller.ButtonRight.pressing() == 1) {

          ParkingControl = 0;
        }

        Controller.rumble("..");
      }
    }```

You never initialize the chassis_speed_value boolean so the code just doesn’t work

you need to say

bool chassis_speed_value =true; when you declare it

(or false if you want)

it’s assumed as false if you write it like:

bool flipflop;

move this

Controller1.ButtonB.pressed( Chassis_Speed );

outside of the while loop (before it, inside main). That call registers the event handler called Chassis_Speed, by placing it inside the loop you register multiple copies which will conflict.

4 Likes

you are using controller.axis3.value() which is a value between -127 and 127 it might be easier to use .position(percent) for understanding what is going on

2 Likes