// set pin numbers:
const int ledPin1 = 13;
const int ledPin2 = 12;
const int ledPin3 = 11;
// Variables will change:
int ledState1 = LOW;
int ledState2 = LOW;
int ledState3 = LOW;
long previousMillis1 = 0; // will store last time LED was updated
long previousMillis2 = 0;
long previousMillis3 = 0;
// 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 = 1000;
long interval3 = 1500;
void setup() {
// set the digital pin as output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop()
{
ledblink1();
ledblink2();
ledblink3();
}
void ledblink1(){
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(ledPin1, ledState1);
}
}
void ledblink2(){
unsigned long currentMillis = millis();
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(ledPin2, ledState2);
}
}
void ledblink3(){
unsigned long currentMillis = millis();
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(ledPin3, ledState3);
}
}