PROS Question


#1

this might be a dumb question, but I’ve never worked with PROS before, so do I declare my motors in all of the cpp files or how am I able to define the motors once and use them in other files?


#2

I had the same problem when I started a few weeks ago. Only define the motors in one file - any file. Then, for each motor/sensor/variable/function that needs global scope, in your “main.h” file, declare each of those at the top of the file. Add the extern keyword at the beginning. So, each of your motors will have the following syntax:


extern pros::Motor motor1;
extern pros::Motor motor2;

Run prosv5 make clean (or pros make clean if you’re running on Cortex) and then pros make. I tend to do that every time I make a change to main.h.


#3

@The Electrobotz has the correct answer.

To clarify, you should define the motors in any one C++ source file (not just any file) and include them in a header file such as main.h.


#4

Sorry, that’s what I meant. By any file I was referring to any source file. I apologize for the confusion.