// --------CONSTANTS--------------- // the pin numbers for the LEDs const int led_1_Pin = 4; const int led_2_Pin = 7; const int led_3_Pin = 8; // the pin number for the button const int inputSignal = 2; // number of millisecs the Led's are off const int led_1_OffDuration = 3000; const int led_2_OffDuration = 3000; const int led_3_OffDuration = 3000; // number of millisecs that Led's are on const int OnDuration_Led1 = 3000; const int OnDuration_Led2 = 3000; const int OnDuration_Led3 = 3000; //------------ VARIABLES--------------------- // used to record whether the LEDs are on or off byte led_1_State = LOW; byte led_2_State = LOW; byte led_3_State = LOW; unsigned long currentMillis = 0; unsigned long previousOnBoardLedMillis = 0; // will store last time the LED was updated unsigned long previousLed_1_Millis = 0; unsigned long previousLed_2_Millis = 0; unsigned long previousLed_3_Millis = 0; //======================================== void setup() { Serial.begin(9600); // set the Led pins as output: pinMode(led_1_Pin, OUTPUT); pinMode(led_2_Pin, OUTPUT); pinMode(led_3_Pin, OUTPUT); // set the button pin as input with a pullup resistor to ensure it defaults to HIGH pinMode(inputSignal, INPUT); } //======================================== void loop() { currentMillis = millis(); int buttonState = digitalRead(inputSignal); if (buttonState == HIGH) { if (led_1_State == LOW) { if (currentMillis - previousLed_1_Millis >= led_1_OffDuration) { led_1_State = HIGH; previousLed_1_Millis += led_1_OffDuration; Serial.print(previousLed_1_Millis); } } else { if (currentMillis - previousLed_1_Millis >= OnDuration_Led1) { led_1_State = LOW; previousLed_1_Millis += OnDuration_Led1; if (led_2_State == LOW) { if (currentMillis - previousLed_1_Millis >= led_2_OffDuration) { led_2_State = HIGH; previousLed_1_Millis += led_2_OffDuration; } } else { if (currentMillis - previousLed_1_Millis >= OnDuration_Led2) { led_2_State = LOW; previousLed_1_Millis += OnDuration_Led2; if (led_3_State == LOW) { if (currentMillis - previousLed_1_Millis >= led_3_OffDuration) { led_3_State = HIGH; previousLed_1_Millis += led_3_OffDuration; } } else { if (currentMillis - previousLed_1_Millis >= OnDuration_Led3) { led_3_State = LOW; previousLed_1_Millis += OnDuration_Led3; } } } } } } } digitalWrite(led_1_Pin, led_1_State); digitalWrite(led_2_Pin, led_2_State); digitalWrite(led_3_Pin, led_3_State); } //========================================END