Have a look at “blink without delay” : http://arduino.cc/en/Tutorial/BlinkWithoutDelay
It uses the time in milliseconds to determine what should happen at a certain time.
+1 to BWD.
drmk, what’s happening with your code (that needs to be put inside “code tags”, see below) is that instead of starting one thing then letting it go and immediately starting the next, your code is trying to mind only one thing at a time from start to finish. And that is even if you set up pin 13 to run the second motor. Those delays are the same as just standing and doing nothing.
BlinkWithoutDelay is cool even with the non-critical errors it has but the explanation is not as good as this one:
Here’s an extract from the heart of it. Nick Gammon uses Arduino code while always explaining why along with what so you get both.
Let’s look at an analogy. Say you want to cook breakfast. You need to cook:
Coffee - takes 1 minute
Bacon - takes 2 minutes
Eggs - takes 3 minutes
Now a seasoned cook would NOT do this:
Put coffee on. Stare at watch until 1 minute has elapsed. Pour coffee.
Cook bacon. Stare at watch until 2 minutes have elapsed. Serve bacon.
Fry eggs. Stare at watch until 3 minutes have elapsed. Serve eggs.
The flaw in this is that whichever way you do it, something is going to be cooked too early (and get cold).
In computer terminology this is blocking. That is, you don’t do anything else until the one task at hand is over.
What you are likely to do is this:
Start frying eggs. Look at watch and note the time.
Glance at watch from time to time. When one minute is up then …
Start cooking bacon. Look at watch and note the time.
Glance at watch from time to time. When another minute is up then …
Put coffee on. Look at watch and note the time.
When 3 minutes are up, everything is cooked. Serve it all up.
In computer terminology this is non-blocking. That is, keep doing other things while you wait for time to be up.
So go to the link, get the whole story, see the evolution of the code from blink 1 led to blink many and you will come out with a very different, very effective view on how to use microcontrollers. The next step is state machines.
About code tags. Code has parts that web html does not display literally if you just paste it in.
Above your forum post edit window there’s a row of smileys and above that, click-buttons.
The # button makes “code tags”. You either click the # button and paste your code between or highlight the code and click the button and the tags go around the highlit part.
This is explained in the forum sticky thread with the before you post read this title, but you musta forgot.