Adding and Deleting Source Files
As your project becomes bigger, you should split it into individual
source files to keep a clear structure.
Having separate source files also reduces compilation time, at
least if you decide to use .CPP files instead of .INO files,
see later.
The resulting program will be identical, independent of having one or
multiple source files. It's just a matter of organization of your sources.
Adding a new source file
- In the menu, click vMicro > Add
Code:
1 |
|
Adds a new, empty .ino file to your project |
2 |
|
Adds an empty .cpp file and a corresponding, empty .h file |
3 |
|
Adds an empty .c file and a corresponding, empty .h file |
4 |
|
Adds a .cpp and a .h file containing a skeleton c++ class |
5 |
|
Adds a board.txt file to the project. The board.txt file has
the same purpose and structure as the Arduino BOARDS.TXT and
PLATFORM.TXT files, and can be used to override settings from
BOARDS.TXT and PLATFORM.TXT for this project. The
resulting board and platform settings are those from BOARDS.TXT
and PLATFORM.TXT, superseded by the settings from the project
specific board.txt file. |
5 |
|
Adds a board.txt file to the project, along with a debugger_launch.json file, allowing fine tuning / configuration of the hardware debugger.
This allows custom configuration of the debugger as explained further here. |
After clicking the menu item, a new and empty .INO, .C or a .CPP file are
added to your project. You will be prompted for a filename. Enter the
filename without the extension.
All three file types are used to write source code.
What is the difference between these file types?
- Arduino .INO files are the Arduino
standard. When compiling, Visual Micro treats all .INO files as they
were one file. That's why you don't have to deal with include files (.H
extension) as long as you are using .INO files only.
- .C files are used to write code that is written in
the C language. Unless you have special reasons, you should not use .C
files, because the C language has no obvious advantages over the
language Arduino uses normally and can cause compatibility issues.
Mixing C and C++ in one project requires profound knowledge of the
languages and the compiler.
- .CPP files are used to write code that is written
in the C++ language. This is the same language the .INO files use. Along
with the .CPP file, Visual studio also creates a matching .H file.
Which file type shall I use?
This article tells you
more about the difference between .INO files and .CPP files and helps you in
choosing the right file format.
Adding Existing Source Files
Use the Project > Add Existing Item menu command to add
existing source files. These files can be located anywhere on your disk, not
only in your project folder.
If you want to remove a file from your project, click on it in the
solution explorer and press [Del]. If you do so, a box
appears that lets you choose between removal and deletion.
Removing a file means that it is no longer part of your
project, but it remains on your disk. You can add it again later by using
Project > Add Existing Item.
Deleting a file will remove it from the project and delete the
file from your hard drive as well.
Some of the methods shown above make your
project incompatible with the original Arduino IDE.
If you plan to use
such a project again in the original IDE,
Follow these steps to make your project compatible again.
Adding Source Files from Other Projects - Sharing Source Files Among Projects
If you have multiple projects and want to share certain source files among
them, then Visual Micro offers a convenient way for it.
- Open a Windows Explorer window and navigate to the project where the source
files are stored, that you want to share.
- Navigate to the project that shall share
these files with the first project
- Right mouse click, and choose "Create
Shortcut", this creates shortcuts of these files in this project folder
- Remove the "Shortcut" from the file names of
the shortcuts, so that e.g. "myfile - Shortcut.cpp" becomes "myfile.cpp"
- Add the shortcuts to your project in the same
way as you would add "real files", as described above