Claw and Arm - VEX C++

Get more with VEXcode
We recommend you transition to our new software. VEXcode has both block-based and text-based options, that work on Chromebooks, iPads, Android tablets, Windows and Macs. Visit code.vex.com for more details on how to download VEXcode.
VEX Coding studio has been discontinued and is no longer available for download. Already downloaded? The program will continue to function but will no longer be supported.
Users who transition to VEXcode can migrate their C++/C++ Pro projects to VEXcode Text by following this article.

This example program shows how to program the V5 Clawbot to use remote control values to move your robot's claw and arm.

ArmClawController.vex

robot-config.h
using namespace vex;
vex::brain Brain; 
vex::motor LeftMotor (vex::PORT1, vex::gearSetting::ratio18_1,false); 
vex::motor RightMotor (vex::PORT10, vex::gearSetting::ratio18_1,false);
vex::motor ClawMotor (vex::PORT3, vex::gearSetting::ratio18_1,true); 
vex::motor armMotor (vex::PORT8, vex::gearSetting::ratio18_1,true);
vex::controller Controller1 = vex::controller();
main.cpp
#include "robot-config.h" 

int main() {

    //Use these variables to set the speed of the arm and claw.
    int armSpeedPCT = 50;
    int clawSpeedPCT = 50;

    while(true) {
        if(Controller1.ButtonUp.pressing()) {
            ArmMotor.spin(directionType::fwd, armSpeedPCT, velocityUnits::pct);
        }
        else if(Controller1.ButtonDown.pressing()) {
            ArmMotor.spin(directionType::rev, armSpeedPCT, velocityUnits::pct);
        }
        else {
            ArmMotor.stop(brakeType::brake);
        }

        if(Controller1.ButtonA.pressing()) {
            ClawMotor.spin(directionType::fwd, clawSpeedPCT, velocityUnits::pct);
        }
        else if(Controller1.ButtonY.pressing()) {
            ClawMotor.spin(directionType::rev, clawSpeedPCT, velocityUnits::pct);
        }
        else {
            ClawMotor.stop(brakeType::brake);        
        }

        task::sleep(20);
    }

}
How it works

First, the  main function is declared. An infinite while loop is created so that the program can pull the remote control values every iteration.  This loop causes the program to run forever.

Next, if ButtonUp on the controller is  .pressing, the arm motor will spin forward.

If ButtonDown on the controller is  .pressing, the arm motor will spin backward.

If neither button is being pressed, the armMotor will  stop.

Then, if ButtonA is  .pressing, the arm motor will spin forward.

If ButtonY on the controller is  .pressing, the arm motor will spin backward.

If neither button is being pressed, the armMotor will  stop.

Then, add a  sleep task for a short amount of time to prevent wasted energy.