Go Down

Topic: multiple patches (Read 564 times) previous topic - next topic

1mpar

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

CrossRoads

#1
Aug 18, 2011, 05:09 pm Last Edit: Aug 18, 2011, 05:18 pm by CrossRoads Reason: 1
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: [Select]

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
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

zepp

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.
I'm here to learn and help when I'm able :)

CrossRoads

Sounds like it. I've never done any C programming.  I just found a way to make the IDE work for me.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

zepp

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

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 :)
I'm here to learn and help when I'm able :)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy