Pages: [1]   Go Down
Author Topic: how do you brake a single sketch down to multiple sketches ?  (Read 388 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been using Ardunio for about a year now and I need help.
I have looked for resources to figure out how to refer to another sketch from the sketch you are programming. My code has gotten big enough to break a sketch down into smaller sketches.
Does Ardunio use dot notation or some other method to refer to the other sketch?
EG
Code:
"sketch1"

void setup(){
sketch2.method1();
}

Code:
"sketch2"

void setup(){
Serial.begin(9600);
}

void loop(){}
void method1(){

Serial.println("Hello World");
}

is this right or wrong?
I am being buried under the never ending sketch.
« Last Edit: February 14, 2013, 07:59:24 am by Alex_the_Lion » Logged

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

Create a new tab, naming the file associated with that tab with a .ino extension. All .ino files are merged at compile time.

Nothing needs to be done to call a function defined in another .ino file, since the compiler will only see one .cpp file when it gets called.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But remember there can be only one one setup() and one loop() function.
Logged

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

what you are saying PaulS is you can refer to another method in an .ino file by the method name only. If I understand you correctly.
Logged

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

Quote
what you are saying PaulS is you can refer to another method in an .ino file by the method name only. If I understand you correctly.
Yes. You do.
Logged

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

thank you for your help PaulS
Logged

0
Offline Offline
Shannon Member
****
Karma: 160
Posts: 10416
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If parts of the sketch might be useful in other projects, then consider encapsulating that part in a library.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: