Looking at Multi-blink, I get lost in a hurry. I could probably work it out but, it is not a beginner sketch imho.
http://arduino.cc/playground/Code/MultiBlinkHow about blinking 5 leds at individual rates without delay! The sketch could be made smaller but, it should be easy to see a pattern.
/* Blink without Delay
Based on Blink without Delay
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to set pin numbers:
// Pin 13: Arduino has an LED connected on pin 13
// Pin 11: Teensy 2.0 has the LED on pin 11
// Pin 6: Teensy++ 2.0 has the LED on pin 6
const int led1 = 13; // the number of the LED pin
const int led2 = 5; // the number of the second LED
const int led3 = 6; //3rd
const int led4 = 7; //4th
const int led5 = 8; //5th
// Variables will change:
int ledState1 = LOW; // ledState used to set the LED
int ledState2 = LOW; // ledState used to set the LED
int ledState3 = LOW; // ledState used to set the LED
int ledState4 = LOW; // ledState used to set the LED
int ledState5 = LOW; // ledState used to set the LED
long previousMillis1 = 0; // will store last time LED was updated
long previousMillis2 = 0; // will store last time LED was updated
long previousMillis3 = 0; // will store last time LED was updated
long previousMillis4 = 0; // will store last time LED was updated
long previousMillis5 = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval1 = 500; // interval at which to blink (milliseconds)
long interval2 = 700; // interval at which to blink (milliseconds)
long interval3 = 800; // interval at which to blink (milliseconds)
long interval4 = 400; // interval at which to blink (milliseconds)
long interval5 = 550; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis1 > interval1) {
// save the last time you blinked the LED
previousMillis1 = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState1 == LOW)
ledState1 = HIGH;
else
ledState1 = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led1, ledState1);
}
if(currentMillis - previousMillis2 > interval2) {
// save the last time you blinked the LED
previousMillis2 = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState2 == LOW)
ledState2 = HIGH;
else
ledState2 = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led2, ledState2);
}
if(currentMillis - previousMillis3 > interval3) {
// save the last time you blinked the LED
previousMillis3 = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState3 == LOW)
ledState3 = HIGH;
else
ledState3 = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led3, ledState3);
}
if(currentMillis - previousMillis4 > interval4) {
// save the last time you blinked the LED
previousMillis4 = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState4 == LOW)
ledState4 = HIGH;
else
ledState4 = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led4, ledState4);
}
if(currentMillis - previousMillis5 > interval5) {
// save the last time you blinked the LED
previousMillis5 = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState5 == LOW)
ledState5 = HIGH;
else
ledState5 = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led5, ledState5);
}
}