Tabs in the editor - how can I use them?

I feel stupid for asking this, but I've been using Arduino and the editor for years and I just noticed on the top right side there is a button to add tabs to the code editing window to create multiple files of code.

Is this a way to work on multiple unique programs at one time, or is this a way to break my long programs into sections that all compile for one download? (I would much, much prefer the later.) It didn't seem to compile when I broke working code into separate tabs, but I haven't explored it fully and could have simply not declared the right things.

break long into shorts and for your own classes to name a few uses.

I don't understand. Long and short variables? Long and short functions? In one compiled piece of software?

Organization primarily.
I take the concept to extreme.

1 Like

So you have one long program and you want to break it up into shorter pieces, tabs work for doing the thing.

Or you have secret info like passwords that you can keep in a separate file/tab so that when you share code the secret stuff is not shared.

Or if you want to edit a library, pull the library code into tabs and edit away.

... this is seen often in ESP32/ESP8266 sketches and I suspect the Arduino brand of IoT boards, too.

I like to put structs in a tab by themselves.

Same with State Machine code sections.

Give the tab a name like SecretStuff :nerd_face:.

OK, thanks you guys. I'll need to experiment more if I can get all tabs to compile into one.

I made a 2nd tab from a good chunk of software, moved some of the global declares into the 2nd tab, and then tried to compile the code. It didn't work and complained that the moved variables were not declared. I didn't find any Arduino written information that discussed how to use tabs.

I am understanding (correctly or not?) that it should treat all the tabs like one piece of software. I do that with Microchip assembly and create a hundred little included files, but when I have to do an Arduino (Mega), I always have one extremely long list of code that can have thousands of lines and take a minute to scroll from place to place if I can find what I'm looking for at all.

You need to include these tab names in your .ino file.

1 Like

That makes a lot of sense. I guess I was thinking the IDE was smart enough to do it for me.
So in the beginning of the first, main file I add something like:

#include functionA.ino, functionB.ino ; ?

...Not sure of the syntax right now but I can look that up.

#include "MyBitmap.h"
#include "certs.h"

Name the tabs with a .h at least. Consider the ino to be a workbook. and the .h and .cpp tabs individual portions.

1 Like

It IS IF you do not give the tab any extension as it defaults to .ino and will be handled by the Arduino build system prior to the forward declarations. All of this preprocessing happens before the C++ compiler.

Arduino Web Editor (and thus Arduino IoT Cloud as well) have a "Secret tab" feature:

On Arduino Web Editor, this is a web form-based tab named "Secret", but if you download the sketch to use locally with the Arduino IDE, it becomes a file in the sketch named arduino_secrets.h

I see, interesting. I am a Arduino Web Editor virgin, just not my style. But good to know.

  • Ray

Same here. I guess I'm too old for all this "cloud" stuff. But even though I don't use it myself, I try to keep up on it so that I can effectively help out those who do choose to use it.

1 Like

Well I'm definitely in the 'old' category, but I justified my Surface Pro based on the need to power through the locally installed IDE. It would be most unhealthy if wife found out that the old Samsung tablet would have been adequate (the wife got the Samsung as a hand-me-down and those savings help me justify the Surface Pro.)

2 Likes

You to! I'm waiting a few months before complaining the Surface Pro is too slow and I need a more, more, more. Now to figure out the justification.

Tabs are read (joined) by the compiler in alphabetical order. So first.ino comes before second.ino and this one before third.ino. But if you add fourth.ino it will then be second…

The exception is that the .ino file that matches the sketch folder name is first in the concatenation order.

For example:

Foo/
β”œβ”€β”€ Bar.ino
β”œβ”€β”€ Baz.ino
└── Foo.ino

The concatenation order is:

  1. Foo.ino
  2. Bar.ino
  3. Baz.ino