VCS Example Program with Controller - C++ - Tank Control

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 your robot to use remote control values to move your robot.

TankControlC.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, true);
vex::controller Controller1 = vex::controller();
main.cpp
#include "robot-config.h"

int main() {
    
    while(true) {
        LeftMotor.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct); //(Axis3+Axis4)/2
        RightMotor.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);//(Axis3-Axis4)/2
        
        vex::task::sleep(20); 
    }

}
How it works

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

Next, the leftMotor and rightMotor are set to spin forward using the controller  Axisvalues as the velocity value.

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