Help with laser spirograph code

Hello,

I am totally new to arduino so please bear with me.

I am currently building a 4 motor laser spirograph controlled by arduino. I have a lot of patterns worked out but just put one in the example below to show what I have so far. What I would like to do is have the laser (connected to pin 13) to flash repeatedley whilst the motors are running at the various speeds. I have tried using the delay function but it is only making the laser flash on and off once in the pattern everytime it loops around (hope that makes sense).

Heres what I have so far.

int m1Pin = 3; // Motor 1 connected to PWM pin 3
int m2Pin = 5; // Motor 2 connected to PWM pin 5
int m3Pin = 6; // Motor 3 connected to PWM pin 6
int m4Pin = 9; // Motor 4 connected to PWM pin 9

void setup()
{
pinMode(13, OUTPUT);

}

void loop()

{
{
digitalWrite(13, HIGH);
delay(150);
digitalWrite(13, LOW);
delay(150);
}

// pattern 1
analogWrite(m1Pin, 115);
analogWrite(m2Pin, 77);
analogWrite(m3Pin, 66);
analogWrite(m4Pin, 152);
delay(5000);

}

Would really appreciate any input on this. I know I have probably done it totally wrong so any help is totally appreciated.

Cheers

Richard

Take a look at the blink without delay tutorial

  {
    digitalWrite(13, HIGH);
    delay(150);
    digitalWrite(13, LOW);
    delay(150);
  }

Why are these curly braces here?

Thanks AWOL looking at it now.

PaulS - Probably a noob mistake. Guess they shouldn't be there?

Guess they shouldn't be there?

No. To me, they scream "clueless". You don't want your code doing that. Get rid of them to shut them up.

Right ok, thanks PaulS

AWOL - that's worked a treat. Thank you.

Sorry another question.

Code so far

int m1Pin = 3; // Motor 1 connected to PWM pin 3
int m2Pin = 5; // Motor 2 connected to PWM pin 5
int m3Pin = 6; // Motor 3 connected to PWM pin 6
int m4Pin = 9; // Motor 4 connected to PWM pin 9

const int ledPin = 13;

int ledState = LOW;
long previousMillis = 0;

long interval = 200;

void setup()
{
pinMode(13, OUTPUT);

}

void loop()
{
// here is where you'd put code that needs to be running all the time.

// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;

// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;

// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}

// pattern 1
analogWrite(m1Pin, 115);
analogWrite(m2Pin, 77);
analogWrite(m3Pin, 66);
analogWrite(m4Pin, 152);

//pattern 2
analogWrite(m1Pin, 200);
analogWrite(m2Pin, 200);
analogWrite(m3Pin, 200);
analogWrite(m4Pin, 200);

}

How do I make it play pattern 1 for say 3 seconds and then move onto pattern 2 next still keeping the laser flashing.

Thanks

How do I make it play pattern 1 for say 3 seconds and then move onto pattern 2 next still keeping the laser flashing.

There is nothing magic about programming an Arduino. It is simply a matter of using the language constructs to do stuff the same way you would.

You seem to be stuck at the how would I make the Arduino do this, when really where you are stuck is how would I do this. If you think about how you would do it, using a watch and a note pad, I'm pretty sure you can figure out how to make the Arduino do it.

RicahrdH:
How do I make it play pattern 1 for say 3 seconds and then move onto pattern 2 next still keeping the laser flashing.

Thanks

Read this...... and try to think of how it would assist you.

if you are still in doubt try to google:

site:arduino.cc using milis()

or you can go the lazy man's route and click here.