Is there a tutorial on the introduction to, and the pros and cons of, using tabs in developing a sketch. I'm using IDE2.1.1.
For example, I have found that some variables defined in a sketch tab are accessible in other tabs but some are not. I moved some variable definitions to subsidiary tabs to reduce the clutter in the main tab, and which were not needed there but some I wanted to be accessible between tabs.
I have a suspicion that it is something to do with the order that the tabs are presented to the compiler, which may be in alphabetical order of file name rather than the order in the IDE on the screen (i.e. from left to right). I noticed that after I did a "Save As" that the tabs (except for the main one with setup() and loop()) get shuffled about into alphabetical order.
I have also observed that when an error occurs (say, a missing" ;" or "}"), many other errors will be reported in related tabs - often "not defined in this scope". I guess if the compiler can't recover from an error, this is to be expected.
I haven't investigated in detail as I have been focused on fixing my errors and getting the sketch to work.
That is correct. All the .ino files of your sketch are concatenated into a single file before it is compiled. The concatenation order:
The .ino file that matches the sketch folder name.
All other .ino files in alphabetical order.
So the order of declarations in the sketch are just the same as it would be if you had all the code in the same file, in that order.
The IDE is supposed to show the tabs in the same order as they are concatenated to indicate this to the user in an intuitive manner but unfortunately Arduino IDE 2.x doesn't sort them that way when you add a new tab:
and it is also possible for the user to drag the tabs into a different order:
As explained, all files are concatenated. So you end up with one big file that will be compiled. An error somewhere can result in lots of errors as you have observed. If you enable verbose output during compilation, you can find the location of that one big file; in windows e.g. `C:\Users\yourUsername\AppData\Local\Temp\arduino\sketches\2C93ED8514FF382F64BB06BC8DC4F3ED\sketch. The filename ends with .ino.cpp.
If I have to use multiple ino files, I name them starting with a letter so I can force the sequence; e.g. mySketch, A_setup, B_loop, C_display, D_input etc. One advice would be to have a tab for all your variables (e.g. in the main ino file).
I however do not use multiple ino files, I usually use .h and .cpp files and those problems disappear as snow for the sun In that case I will more than likely end up with something like mySketch, display.h, display.cpp, input.h and input.cpp. All those cpp files are separate compilation units; a mistake like a missing } will result in errors reported for that file.
For a beginner it's something to get used to; but at the end of the day it will prevent you from encountering (nearly all) bugs in the process that creates the big file.
I hadn't used the Arduino IDE for couple of years (so was using V1.18 then) and hadn't run into this problem then. I was thinking of the A,B,C type of tab naming but hadn't tried it.