Some time ago I posted a query asking for advice on combining two or more sketches together in order to make better use of the Arduino Uno that I was using. I was advised to consider “merging” of the two sketches.
This I tried but it didn’t meet my requirements as I want to be able to run the separate sketches simultaneously not consecutively and if I merge two sketches together any delay commands affect the other sketch.
The sketches are related to a model railway layout and I don’t want to have numerous Arduinos around the layout when one Arduino has the capacity to control multiple lights, signals etc.
mcnaugg:
I want to be able to run the separate sketches simultaneously not consecutively and if I merge two sketches together any delay commands affect the other sketch.
imagine I ask you to repeat HELLO 10 times, I'm sure you can do that
imagine I ask you to repeat WORLD 10 times, I'm sure you can do that
those are two different tasks
Now what would it take to hear HELLO WORLD 10 times?
if you apply the instructions for a single word you would need two mouths and synchronize them so that they don't speak at the same time...
Now if you work hard you can see that the instructions are simple, just "repeat HELLO WORLD 10 times"..
To get there you thought about what would need to happen and you changed the instructions, merged the programs.
that's the same thing with your arduino.... you need to write a new program which takes into account the asks from the first and second programs.
alternatively you can get 2 arduinos (the 2 mouths) and add a bit of synchro code so that they do the right thing... usually that option is more complicated than writing a new program