Pages: [1]   Go Down
Author Topic: Multi file arduino sketch  (Read 2365 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Edison Member
*
Karma: 18
Posts: 1170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 2
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The same just happened to me!
Thanks!!!

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

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11153
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 2
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: