char led_red = 23;
char led_yellow = 19;
char led_green = 18;
char led_red_state = LOW;
char led_yellow_state = LOW;
char led_green_state = LOW;
long led_red_previous_millis = 0;
// this variable to store the last time
// the RED led has changed state
int red_led_interval = 1000;
// ON for 1000 ms
// OFF for 1000 ms
void setup() {
// put your setup code here, to run once:
pinMode(led_red, OUTPUT);
pinMode(led_yellow, OUTPUT);
pinMode(led_green, OUTPUT);
}
void loop() {
long current_millis = millis();
if (current_millis - led_red_previous_millis >= red_led_interval)
{
led_red_previous_millis = current_millis;
// now reverse the led's state
if (led_red_state == LOW)
led_red_state = HIGH;
else
led_red_state = LOW;
// control the led accordingly
digitalWrite(led_red, led_red_state);
}
}