Driving two or more vibration motors

Hi,

I'm new to the whole Arduino and programming thing so I guess my question is kind of stupid...

I am currently trying to drive two or more vibration motors with the arduino. The thing is that i would like them both to go off at the same time but do something different. For example: The first one should vibrate for 1 second, meanwhile the second motor would vibrate for 2 seconds and then one would pause for 1 second and the other one for two seconds and so on.

I have worked out how to get both motors to run but now I am stuck. Help is greatly appreciated !

My current code looks like this:

int motorPin = 6;
int motorPin1 = 3;
void setup()
{
pinMode(motorPin, OUTPUT);
pinMode(motorPin1, OUTPUT);
}

void loop()
{
digitalWrite(motorPin, HIGH),digitalWrite(motorPin1, HIGH) ;
delay (1000);
digitalWrite(motorPin, LOW),digitalWrite(motorPin1, LOW);
delay(5000);
}

Thanks in advance !

You need to use the BlinkWithoutDelay principle and use millis() for timing instead of delay()

Here is an example program that blinks 3 LEDs at different rates. Of course, the output pins do not need to drive LEDs.

const byte ledPins[] = {10, 11, 12};
const byte NUMBER_OF_LEDS = sizeof(ledPins) / sizeof(ledPins[0]);
unsigned long startTimes[3];
unsigned long periods[] = {300, 500, 700};

void setup()
{
  for (int led = 0; led < NUMBER_OF_LEDS; led++)
  {
    pinMode(ledPins[led], OUTPUT);
  }
}

void loop()
{
  unsigned long currentTime = millis();
  for (int led = 0; led < NUMBER_OF_LEDS; led++)
  {
    if (currentTime - startTimes[led] >= periods[led])
    {
      digitalWrite(ledPins[led], !digitalRead(ledPins[led]));
      startTimes[led] = currentTime;
    }
  }
}

oscar456:
For example: The first one should vibrate for 1 second, meanwhile the second motor would vibrate for 2 seconds and then one would pause for 1 second and the other one for two seconds and so on.

void loop() {
digitalWrite(motorPin, HIGH);
digitalWrite(motorPin1, HIGH) ;
delay (1000);
// End of 1st second

digitalWrite(motorPin, LOW);  // motorPin was on for 1 second
delay (1000);
// End of 2nd second

digitalWrite(motorPin, HIGH); // motorPin was off for 1 second
digitalWrite(motorPin1, LOW);  // motorPin1 was on for 2 seconds
delay (1000);
// End of 3rd second

digitalWrite(motorPin, LOW);  // motorPin was on for one second
delay (1000);
// End of 4th second

// motorPin1 was off for 2 seconds
}