Coding for a Tray

Hi! I am coding for a tray on our robot. The tray is supposed to go forward when the up arrow is pressed. It’s supposed to go back when the back arrow is pressed.

Unfortunately, I have a problem. When I put in the code, nothing worked. By nothing, I mean our wheels didn’t move when the joystick was pushed, the arms didn’t raise with the buttons, anything. The tray itself didn’t work as well.

I think it may be because I didn’t code for the up and down buttons correctly. I’ve never coded for the arrows, so I think I made a mistake. The following is my code for the tray.

     if(Controller1.ButtonUp.pressing()) { //If button L2 is pressed...
      //...Spin the arm motor forward.
     Tray.spin(vex::directionType::fwd, traySpeedPCT, vex::velocityUnits::pct);
  }
  else if(Controller1.ButtonDown.pressing()) { //If button L2 is pressed...
      //...Spin the arm motor backward.
      Tray.spin(vex::directionType::rev, traySpeedPCT, vex::velocityUnits::pct);

  }
  else { //If the R1 or R2 button is not pressed...
      //...Stop the arm motor.
      Tray.stop(vex::brakeType::brake);
  }       

Please tell me if I coded for the arrows incorrectly! :slight_smile:

that’s all in a while loop right? Just checking once means values will never change from the start of the program.

Also, we can’t see the joystick’s code so we can’t debug it.

4 Likes

The joystick’s code (along with everything else) was working fine, it was only the tray that was weird. :thinking:

And about the while loop. Looking at your reply, I realized it was not in a while loop. I went and put it in one, so hopefully, that solves the problem! :smiley: Thank you!