Arduino IDE tabs

Just recently i discovered that we can use tabs in the Arduino IDE to organize our sketches.
I would like to understand a little bit better how this works, but can’t find so much “easy to understand” information about it.
On the page ( i found:

A sketch can contain multiple files (tabs). To manage them, click on the right-facing arrow just above the scroll bar near the top of the environment. Tabs have one of four extensions: no extension, .c, .cpp, or .h (if you provide any other extension, the period will be converted to an underscore). When your sketch is compiled, all tabs with no extension are concatenated together to form the “main sketch file”. Tabs with .c or .cpp extensions are compiled separately. To use tabs with a .h extension, you need to #include it (using “double quotes” not ).

So, this means that i can for instance write a function on a new tab, let say “void checkButton()”, and then still call it from the loop() function on the main tab by something like “checkButton(button1)”?

What are the different extensions for? No extension, .c, .cpp or .h? Does each have its own functionality?

Is it good practice to use multiple tabs even in small sketches, just maybe to keep things more organized, is it better to keep it in one sketch, or is it personal preference? How do you use?

I remember trying an Arduino Instrument which had a separate tab with the list of notes available (they were in a tab called “pitches.h”). This list had to be imported using #import "pitches.h"
Why is this? Why isn’t this notes list available and needs to be imported, but a function is available and doesn’t need to be imported?

Hmmm, many other questions, but maybe some of the answers to this ones will already help me.
…and maybe there are even other people out there, who had never noticed that we can have Tabs! =)


I think you mean #include, not #import.

Header files (.h files) need to be included into source files for them to have any meaning.

Source files (.ino) all get joined together into one humungous file before compilation, so you don't need to worry about exporting your functions from one file to another.

Certainly the more 'normal' arduino IDE practice of using the standard importation of libraries stored in either the user's library or the arduino's core library is the more popular method. However for functions you create for just one sketch project, the use of tabs helps keep larger sketches easier to deal with. Just don't name them with a .xxx file type and they will automatically get compiled along with the main sketch. I've used tabs on a few sketch project and it's a neat feature, however for any library type code that you plan to make available to many different sketch projects your better off using the normal library #include method.

majenko: I think you mean #include, not #import.

ooops, yes, i did mean #include ;)

Thanks guys!

I usually create the additional files as .ino files and the IDE automatically includes them without needing any #include instruction. The IDE loads the main file first (the one with the same name as the directory) and loads the others in alphabetical order. Global variables defined in a file can be accessed by code in a file that is loaded later, but not one that is loaded earlier.

As you can probably guess I am not a C/C++ programmer when I can avoid it.


i guess my next project will feature some "tab-organized-code"... 8)