Header Files RobotC????

So I want to know how to use header files in robotC. Do I have to save all my files as header files first except main.c and #include them as xyz.h? Or do I keep the files as .c files then #include them as xyz.c?

Header files are not generally used in RobotC (because RobotC is an intentionally simplified Frankenstein of C/C++). I would suggest you keep the .c extension and

#include "xyz.c"

like the competition template does.

You can include files from a different directory by adding a “Directory for User Include Files (common).” View > Preferences > Detailed preferences > Menu level = Expert > Compiler > Include directories.

Will this work. I attached an image.

You still need task autonomous, pre_auton & usercontrol. Unless you have very large sections of code I would suggest putting it all in one file, that way it’s easier to find everything (you don’t need to keep flicking between 6+ tabs).

drive.c, claw.c, mogo.c, etc.:

void drive() {
    // do stuff to do with drive. This will be called 50 times a second in usercontrol


#pragma config(Motor,  port5,           driveLeft,     tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor,  port6,           driveRight,    tmotorVex393_MC29, openLoop, reversed, driveRight)
// lift, mogo, other ports as well
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// This code is for the VEX cortex platform
#pragma platform(VEX2)

// Select Download method as "competition"
#pragma competitionControl(Competition)

//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"

#include "lift.c"
#include "drive.c"
#include "turn.c" // what is this? It sounds like it should be in drive.c
#include "claw.c"
#include "chainbar.c"
#include "mogo.c"

void pre_auton() {


task autonomous() {


task usercontrol() {
	while (true) {
		sleep(20); // only run 50 times a second
		drive(); // call the function that you included at the top (void drive() { ... })

EDIT: also please copy paste your code into

 code] ...  /code]

(no spaces) blocks instead of posting pictures :stuck_out_tongue: It means we don’t need to type up your code again for examples.

Oh sorry I didn’t know how to put the code without taking a picture. And also, what is the difference between sleep and wait1msec. And what do you mean by “// call the function that you included at the top (void drive() { … })”?

And do I just upload the main file to the cortex or all the files?






are all exactly the same.

#include “drive.c” literally just copy pastes the contents of drive.c into main.c. In this case the contents of drive.c is a function called “drive”. The usercontrol code in my example runs (calls) each function (drive, lift, mogo, etc.) multiple times a second.

Just the main file. Before the upload starts the main file will #include all the files you want and the robot will just see one big file.