Micro Need to run two motors

I would like to run two micro motors with different different schemes. One motor on Pin 9 and one on pin 13. I Cannot figure out how to program the Arduino to accomplish this.
This is what I have so far. Hope you can help.

This example code is in the public domain.
*/

// Pin 9 has an MOTOR
// give it a name:
int motor = 9;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(motor, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(motor, HIGH); // turn the Motor on (HIGH is the voltage level)
delay(400); // wait for a second
digitalWrite(motor, LOW); // turn the motor off by making the voltage LOW
delay(600);
digitalWrite(motor, HIGH); // wait for a seconddigitalWrite(led, HIGH); // turn the motor on (HIGH is the voltage level)
delay(600); // wait for a second
digitalWrite(motor, LOW); // turn the motor off by making the voltage LOW
delay(400); // wait for a second
}

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.

Caltoa:
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:
http://www.gammon.com.au/forum/?id=11411

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.

Thank you for the help.