Tabs in Arduino IDE

I saw this post about tabs in IDE .

I am facing the same problem as well, but I still can't get the concept. If I am putting a void in second tab with some local variables, for example:

void anotherfunction(char colour = 'r', byte Flash=255){ //some action } 

then when I am calling it in 1st tab, it should be assigned as ?

void loop { anotherfunction(char col= 'RE', byte Fla=255); } 

I know the col and Fla should be declared before void loop.. but my main point is, do I need to assign another variable or just use same variable as it is? Assuming the variables are all local variables.Or it should be another way around?..

Calling the function:

void loop { anotherfunction(col , Fla); } 

col and Fla have to be defined and assigned a value before calling anotherfunction().

Usually you don't assign a value when defining the function:

void anotherfunction(char colour, byte Flash ){ //some action } 

This is always the same, wether you write it in another tab or not.

1 Like

Hello
Well, I think you shall take a view here:

1 Like

You are not putting a void anywhere. You are defining a function that does not return any data, hence it is void. If you were defining a function that returned an int would you refer to it as an int ?

1 Like

I am not understanding the question or you are not understanding the use of tabs.

I use tabs in virtually every sketch I write. It greatly uncomplicates my main ino file.

Your typical sketch looks like this:

include files
declarations
globals
setup()
loop()
function1()
function2()
etc.

To unclutter the sketch, you simply put the functions into separate tabs.

tab1:
declarations
globals
setup()
loop()

tab2:
function1()

tab3:
function2()

tab4:
etc.

You do not put includes, declarations and globals in the tabs. It would be as if you did this in a monolithic sketch:

include files
declarations
globals
setup()
loop()
more declarations
function1()
more globals
function2()
etc.

This might work, but usually not.

The compiler always loads the main ino file first. The load sequence of the other tabs is immaterial.

@SteveMann there is one crucial thing missing from your explanation and that is how you name the files held by the tabs. The file extension is important. I will let you explain

doesn't giving it a .ino suffix make things a lot less restrictive because of the arduino pre-processing?

i think reply #2 basically addressed the issue

Nowhere in this topic has the file extension for the tab files been mentioned until reply #6

but it appears her question was really about the arguments and syntax of the arguments to the function called in loop()

the file extension I am using is .ino

I don't know if "less restrictive" is the right term. It does give you the convenience of automatic function prototype generation --- that feature usually works correctly.

However, it smashes all the .ino files into a single translation unit before handing it off to the compiler. It may be important to know this and the order in which it happens (based on file name after the main .ino).

So, while adequate for newbies, the above does not provide truly modular code that is maintainable and reusable. It is also not suitable for large projects. Also, I prefer to supply my own function prototypes and thus prefer the .h / .cpp file method …. see my Reply #5 Here.

Using .ino as the file extension for the tab files is correct. It causes the pre-processor to join all of the .ino files. including the main one, into one file before compiling the program so local and global variable behave as though they were declared in one .ino file but the joining together of the files does not change the order in which functions and variables are declared

However, you say that you are calling a function in another tab using

anotherfunction(char col= 'RE', byte Fla=255); 

Is that how you would call the function if it were in the same file ?

i don't believe the above is valid. it looks like a "declaration", a prototype, but aren't default values only specified in the "definition"?

That's my point. It does not call the function wherever it is located

isn't that what i said in replay #9 and what MicroBahner said in replay #2

Yes, that is what I was reiterating hoping that @stephanie9 would get the point at last

The OP's syntax is, in fact, valid and correct:

This provides default values for the variables 'colour' and 'Flash'.

Yes I know. That's why I wrote 'usually'. If someone doesn't know about functions at all, I don't think he knows about default values. Defining default values isn't used often in standard functions - opposite e.g. in classes ( methods and especially constructors ). But of course you can do.

I think they are specified in the declaration ( function prototype ). The compiler must know about it when the function is called. The definition may be in a separate file. But of course, sometimes declaration and definition ist the same.

The default suffix is ".ino" which the compiler just appends to the main ino file as it finds them. I have experimented with libraries where I create two tabs: "xyz.h" and "xyz.cpp".

I think ".c" is also acceptable.