Pages: [1]   Go Down
Author Topic: multiple patches  (Read 461 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm preparing a performance using arduino and I made 5 different patches (.pde).
what's the best way to put them together?
if I put all the code in the same window I'll have a huge code and it'll be hard to find the specific parts.
is there a way to separete the parts in different tabs, like when i add a .h file?
how can I make it?

thanks,
1mpar
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 436
Posts: 23634
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, in the upper right of the IDE there is a create tabs button, put the guts of each sketch in each one. There can only be one void loop.
How do the different sketches get called?
I have done something like read the serial input in void loop(){ , then use switch:case to jump to the section to be run, at the end it goes to back to loop to wait for the next command.
I also named the tabs  like a_tab1, b_tab2, c_tab3 so they show in order across the screen, and I think perhaps they put together that way for compiling also.
I have to look, I think the sketch gets saved with the name of the first tab.
I break my code up like this to make it easier to find stuff on big (10-12K) programs:
a_comments
b_preset
c_setup
d_loop1
e_loop2
f_other_stuff, maybe function, pitches.h, etc.

Code:
void loop(){
if (Serial.available() >0){
sketchNumber = Serial.read();
}
switch (sketchNumber){
case 0:
// do nothing here for this case
break;  // ends the switch, goes out to check for serial data again
 // end of tab 1
// put this at start of tab 2
case 1:
// code
sketchNumber = 0; // reset so it does not repeat
break;
// end of tab 1
 // start of tab 2
case 2:
// code
sketchNumber = 0; // reset so it does not repeat
break;
// end of tab 2
start of tab 3
case 3:
// code
sketchNumber = 0; // reset so it does not repeat
break;
} // closes out switch (sketchNumber)
} // closes out void loop
// end of tab 3
« Last Edit: August 18, 2011, 10:18:28 am by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Fredericksburg, VA
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Kooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I may not be understanding your problem correctly, but this sounds like the very problem that languages like C++ were created to solve.

You could take all of the program erm, "segments", and same them in separate header files, then include them in a main class and call them like functions.

You could call the functions based on time, button presses, or anything else.
Logged

I'm here to learn and help when I'm able smiley

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 436
Posts: 23634
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds like it. I've never done any C programming.  I just found a way to make the IDE work for me.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Fredericksburg, VA
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Kooky
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's just object oriented programming, which is what you described. smiley

I love the simplified C++ in use in the Arduino IDE, as I have limited experience as a programmer (taking online classes currently).

You can take a bunch of functions like

void tacos(){ } and void burritos(){ }

and break them up into different files and call them on the fly. OOP rules smiley
Logged

I'm here to learn and help when I'm able smiley

Pages: [1]   Go Up
Jump to: