Multi file arduino sketch

PaulS:
What kind of file?

Typically, one creates extra .ino files to contain functions that the sketch calls. All .ino files in the sketch directory are opened in separate tabs when the sketch is opened, and are all combined into one .cpp file for compilation.

You can also create header files (.h) and #include them in a sketch. Then, you create a correspondingly named .cpp file in which the functions defined in the header file (if there are any) are implemented.

I want to split my code into 2 files. The main sketch calls a function in another file. In plain C++, I would create another pair of .h/.cpp files to put the function declaration and implementation in. For arduino, should I go with this approach, or instead create a separate .ino file?

Either way, where exactly do I specify that I want the .cpp file to be used while compiling? I can do a "#include "myfile.h" but how do I specify the .cpp file for the compile command line?

1 Like