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
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);
}
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.