int ledPinR = 23; // the number of the LED pin
int ledPinG = 18;
int ledPinY = 19;
int ledState1 = LOW; // ledState used to set the LED
int ledState2 = LOW;
int ledState3 = LOW;
long previousMillis1 = 0; // will store last time LED
long previousMillis2 = 0;
long previousMillis3 = 0;
int interval1 = 1000; // interval at which to blink (milliseconds)
int interval2 = 500;
int interval3 = 2000;
void setup()
{
pinMode(ledPinR, OUTPUT);
pinMode(ledPinG, OUTPUT);
pinMode(ledPinY, OUTPUT);
}
void loop()
{
long currentMillis = millis();
if ( currentMillis - previousMillis1 >= interval1)
{
previousMillis1 = currentMillis; // save the last time you blinked the LED
if (ledState1 == LOW)
{
ledState1 = HIGH;
}
else
{
ledState1 = LOW;
}
}
if ( currentMillis - previousMillis2 >= interval2)
{
previousMillis2 = currentMillis; // save the last time you blinked the LED
if (ledState2 == LOW)
{
ledState2 = HIGH;
}
else
{
ledState2 = LOW;
}
}
if ( currentMillis - previousMillis3 >= interval3)
{
previousMillis3 = currentMillis; // save the last time you blinked the LED
if (ledState3 == LOW)
{
ledState3 = HIGH;
}
else
{
ledState3 = LOW;
}
}
digitalWrite(ledPinR, ledState1);
digitalWrite(ledPinG, ledState2);
digitalWrite(ledPinY, ledState3);
}