Open VEXcode IQ in C++ mode, write your first program, and learn what each piece of the code actually does.
#include "vex.h", main(), and semicolons do.Blocks are great for getting started, but every block is just a friendly wrapper around a line of C++. Moving to text gives you three things blocks can't: precise control (write your own algorithms like PID), readability across long programs, and the same skills used in real engineering. The hardest part is the syntax, not the ideas, you already know the ideas from blocks.
In VEXcode IQ, create a new C++ project. The editor opens with a template that already does the boring setup for you. You only write code inside main().
#include "vex.h"
// VEXcode IQ generates the lines below for you when you add motors / sensors
// in the Robot Configuration menu. You do not type them yourself.
brain Brain;
motor LeftMotor = motor(PORT1, false);
motor RightMotor = motor(PORT6, true); // mounted facing the other way
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// your code starts here
LeftMotor.spin(forward);
RightMotor.spin(forward);
wait(2, seconds);
LeftMotor.stop();
RightMotor.stop();
}
motor LeftMotor = motor(PORT1, false); line for you. It also adds the call to vexcodeInit() inside main(), which wires up your sensors and brain at startup. Never delete that line. You write the code after it.
#include "vex.h" pulls in all the VEX classes (motor, brain, sensors).int main() is the entry point. The program starts at the first { and ends at the matching }.vexcodeInit(); is the IDE-supplied setup call. Always at the top of main.; ends a statement. Forgetting one is the #1 beginner error.Modify the program to drive backward for 1 second instead of forward for 2 seconds. Hint: change forward to reverse and the time.
Two programs with intentional errors. Spot the bug.
#include "vex.h"
// using namespace vex; (auto-included by VEXcode IQ)
brain Brain;
motor LeftMotor = motor(PORT1, false);
motor RightMotor = motor(PORT6, true);
int main() {
LeftMotor.spin(forward)
RightMotor.spin(forward);
wait(2, seconds);
LeftMotor.stop();
RightMotor.stop();
}
motor LeftMotor = motor(PORT1, false);
motor RightMotor = motor(PORT6, false);
int main() {
LeftMotor.spin(forward);
RightMotor.spin(forward);
wait(2, seconds);
}