Go Down

Topic: Multi file arduino sketch (Read 4151 times) previous topic - next topic

Is it possible to break an Arduino sketch into several files (using something akin to an "Include" to point to the 'external' files? The point is to make it easier to navigate through, and edit, a large sketch.


Ah. I thought there might be. No doubt I framed my question improperly: How does one include such a file in the 'main' sketch? What is the syntax of such an include? Where does one store the included file?

KeithRB

In the same directory as the main file. (You should use 1 directory per project)

Could you please point me to the documentation/instructions for including an external file (one I wrote) in an open sketch?

PaulS

Quote
Could you please point me to the documentation/instructions for including an external file (one I wrote) in an open sketch?

What kind of file?

Typically, one creates extra .ino files to contain functions that the sketch calls. All .ino files in the sketch directory are opened in separate tabs when the sketch is opened, and are all combined into one .cpp file for compilation.

You can also create header files (.h) and #include them in a sketch. Then, you create a correspondingly named .cpp file in which the functions defined in the header file (if there are any) are implemented.

Thank you for that clear answer! After a good deal of more or less random effort, something like that understanding came late last night. I was looking for something more complicated, and some sort of directive to explicitly include such files at some specific points in the main program. All, apparently, unnecessary concerns.

Thank you.

PatoPato

The same just happened to me!
Thanks!!!

I tryed as in java to do import of a class that I defined in a tab.

PeterH


I tryed as in java to do import of a class that I defined in a tab.


If you follow conventions for programming in C++ you will have a much better chance for success.
I only provide help via the forum - please do not contact me for private consultancy.

PatoPato



I tryed as in java to do import of a class that I defined in a tab.


If you follow conventions for programming in C++ you will have a much better chance for success.


Sure, but my expertice is in java, and I do it without noticing. Also I "jump" from java to arduino, to processing, and java again... and so one.

Yes,

I need to find the Sketch->Add INO file, menu option.
It seems to be missing.

'Add new ino file', 'new ino file' ?.

I believe beginners should use Atmel Studio 6, before moving onto something as complex as the arduino environment.

Robin2


Yes,

I need to find the Sketch->Add INO file, menu option.
It seems to be missing.

'Add new ino file', 'new ino file' ?.


The little button with the 'v' on the RHS is a menu with New Tab as one of the options.


Quote
I believe beginners should use Atmel Studio 6, before moving onto something as complex as the arduino environment.


This has to be a wind-up / troll

...R

Go Up