Tabs Tabs Tabs!

New(ish)bie... I'm slightly confused about Tabs.

So:

  • I have my sketch folder (called my_sketch).
  • Inside this file I have the main my_sketch.ino file
  • I then create a new tab which I call my_new_tab.ino

Is that it? Can I add code into my_new_tab...

Or...

Am I correct in understanding that I need to add #include <my_new_tab.something> in my_sketch.ino?

I

Is that it? Can I add code into my_new_tab...

Yes.

Am I correct in understanding that I need to add
Code: [Select]
#include <my_new_tab.something>
in my_sketch.ino?

No, you are not correct. You do not need to #include it.

I then create a new tab which I call my_new_tab.ino

You don't need the .ino extension. The extension will be added when you save.

OK. Thanks. Following on from this, how do I pass variables from my_new_tab (which I've made a cpp file) into my_sketch?

(deleted)

if you made a .cpp, then you need a .h

When I move my variable "button" over into my_new_tab the compiler is logging:

error: 'button' was not declared in this scope
pinMode(button, INPUT);

Do I need to declare it as a blank variable in my_sketch first? The variable value (in my_new_tab) is required during setup (as it is informing which pin the button is connected to).

Juraj:
if you made a .cpp, then you need a .h

This is getting complicated!!!

I'm looking to place my programmable variables in my_new_tab, with the static code running in the main sketch. Am I best having 2 ino files? What are the advantages of having a .h & a .cpp?

ino files a concatenated together by the Arduino sketch preprocessing. everything is global in ino files.
with h and cpp you can control the visibility/scope of variables and functions to other parts of the program. and h and cpp are the way if you plan to make a library.

Juraj:
ino files a concatenated together by the Arduino sketch preprocessing. everything is global in ino files.
with h and cpp you can control the visibility/scope of variables and functions to other parts of the program. and h and cpp are the way if you plan to make a library.

Ah... Gotcha. The h file being the central "hub" where you would place all global variables. Sounds like ino files will do the job for me today.

I see the main issue that I was experiencing now...

I was trying to declare integers for my pin mappings, before the setup function.

As I was putting these into the new tab, they weren't being declared before the setup function was called.

I've swapped this around now so all the initial constants & integers, etc are declared in the main_sketch, with the setup & loop functions then operating from my_new_tab.

Works a treat.