int redLed = 12; // pin for red LED
int yellowLed = 8; // pin for yellow LED
int greenLed = 7; // pin for green LED
int buttonPin = 2; // pin for the push button
void setup() {
// Initialize LED pins as outputs
pinMode(redLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(greenLed, OUTPUT);
// Initialize button pin as input with pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Turn on red LED
digitalWrite(redLed, HIGH);
// Wait for button press to proceed
waitForButtonPress();
digitalWrite(redLed, LOW);
// Turn on yellow LED
digitalWrite(yellowLed, HIGH);
delay(500); // Wait 1 second
digitalWrite(yellowLed, LOW);
// Turn on green LED
digitalWrite(greenLed, HIGH);
delay(2000); // Wait 1 second
digitalWrite(greenLed, LOW);
}
void waitForButtonPress() {
// Wait until the button is pressed
while (digitalRead(buttonPin) == HIGH) {
// Do nothing; stay in this loop until the button is pressed
}
// Debounce delay to avoid multiple readings
delay(50);
}