How to program certain buttons to work certain parts of the robot?

Seems like a general question but right now we are using some pretty weird buttons for our driver control and I want to program it so that the joysticks actually control the wheels and that the buttons aren’t all over the place for each intake and tray… I think I have to do something like: if(buttonsomething.ispressed) but I’m not sure. This is my first tournament and first driver control code. Thanks, also I’m using vexcode v5 text

Say you want L2 to trigger a motor forward. It would be something like

if Button.L2 is pressed run this motor forward or reverse
Else stop the motor

Buttons are a b x y up down left right l1 l2 r1 r2

1 Like
if(Controller1.ButtonB.pressing()) {
else if(Controller1.ButtonA.pressing()) {
else {

would this work?

1 Like

You might want to add a curly at the end of the else loop, and motor.stop(brakeType::brake); or brake type hold. I think that is how it is formatted

1 Like

Yeah sorry I didn’t copy paste the whole program into the reply so I missed some spots but basically that would work right? And the button for left and right theres a left 1, right 1, left 2, etc???

Yes, that looks to me like it would work.

image image what would these be called? is it formatted ButtonLeft1

Those are called Axis. The up/down triangles represent the vertical axis on the joystick, the left/right triangles represent the horizontal axis of the controller.

To get their values use:


You can replace the “1” in “Axis1” to the number of the axis you are trying to get.

1 Like

but would it be Controller1.AxisUp1.pressing

since theres an up and a down, unless it already knows since youre pointing it which direction

or would it be Controller1.ButtonAxis1 or something

or Controller1.Axis1.up

Joysticks do not behave like buttons. To check if they are being used. Check if the value is not equal to zero.

Sometimes the joystick is sticky, and doesn’t return to zero when it is released. To fix this, you can create what is known as a “dead zone”. It used a range of values to compare against instead.

if(Controller1.Axis1.value() < -5 || Controller1.Axis1.value() > 5)
// Do stuff
1 Like

What does the value do?basicallg -5 is when u do down on the joystick a 5 is up right

The value is just how far the joystick is moved. A positive number is either up or right, a negative number is either down or left.


if(Controller1.Axis1.value() < -5()) {




else if(Controller1.Axis1.value() <5()) {




else {




There are a few things to note.

Your if statements are not formatted correctly. Refer to my example above for proper formatting. If you’re new to programming, you may want to look into using VEXCode blocks, since C++ is not an easy starter language.

I’m assuning you are programming a drivetrain. If so, you probably want to be using Axis 2, since Axis 1 goes left and right. You also probably want to use the value to control the speed of your motors.

Here is an example. Don’t copy-paste it in, not only is that bad practice, but it was all typed out on mobile, so there will be mistakes.

  // Setting the controller values to variables makes the code a bit cleaner.
  int leftValue = Controller1.Axis3.value();
  int rightValue = Controller1.Axis2.value();

  // Checks of values are outside of deadzones.
  if(leftValue > -5 && leftValue < 5)
    leftValue = 0;

  if(rightValue > -5 && rightValue < 5)
    rightValue = 0;

  // Set the velocities.

  // Actually moves the motors.