Go Down

Topic: Combining Sketches (Read 889 times) previous topic - next topic


I am a student and new to Arduino microcontroller.  My project is a Wireless Environment System which includes sensors (photocell, temperature and humidity).  I decided to write the sketches (program) in section and now I have to combine them.

Can someone give me suggest on how to combine my sketches so they can work together.


You read this, didn't you?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.



Here's one way:

Put all the parts that go before void setup together.
Put all the parts in void setup together.
Write a blink without delay section to run the rest quasi- concurrently:

add these to your declarations:
unsigned long previousMillis();
byte sketchSelect = 0;
Code: [Select]

void loop(){
if (millis() >=previousMillis){
previousMillis = previousMillis+100; // each gets 100mS, then next one start
sketchSelect = sketchSelect +1;
if (sketchSelect == 4){ sketchSelect = 1;}
switch (sketchSelect){
case 1:
// sketch 1
case 2:
// sketch 2
case 3:
// sketch 3
} // end switch
} // end loop
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.


This is Grumpy Mike's page:


Go Up