VEX V5 - Introduction to VEX Code

Objective

Understanding the C++ text code syntax and how to relate that to VEX robotics.

Tools and References

VexCode V5 is the program of choice for all things code with VEX robots. It is based around C++, which is an object oriented programming language, meaning data is stored inside objects, rather than only being manipulated through functions. Here is an assembly of some useful pages that may help. The first is the Vex Help pageVisit the VEX Help Page that covers all things vex.

Also see our C++ Cheat Sheet

VEX V5 C++ : Basic C++

Learner’s Guidance

Variables and Types

When defining variables in code, it is important to keep track of what kind of variable it is. All variables that are defined outside of the int main() and not exclusive to functions are called global variables, meaning they can be accessed by any function or command in your code. If a variable is defined solely inside of a function, they are called local variables.

The Different types of variables are listed below

int number1 = 14;     //integer values are called int

float number2 = 14.1234;      //floating point values are decimals of higher accuracy

double number3 = 14.123456789;    //double floating point values have twice the accuracy of floats

bool perhaps = true;        // booleans are true or false values, useful for conditions

Brain Screen and Printing

The V5 Brain uses a touch screen as a user interface. Printing to the screen is one of the most useful functions of the brain, as it allows us to monitor variables and certain outputs that are critical to our code and therefore the robots performance. It also can be used as a code selector for running programs that have multiple outcomes, depending on the desired result.

Below is example code for printing basic text and variables on the screen

//using just the print function will print at the very top of the screen.
brain Brain;
.
.
.
Brain.Screen.print("this is the top of the screen.");

//using printAt will make you choose where on the screen you
//want to print using x and y coordinates that relate to pixel position on the screen.
Brain.Screen.printAt(1,50,"this is slightly lower than the previous line.");

//You can also print ints and doubles using the following
Brain.Screen.print("%d",(int) value);
Brain.Screen.print("%.2f",(double)value);

https://gist.github.com/gkirkman/9928e15c52ef9fd8d88ce3648b0cb8f1