//MUHD AFIF SYAUQIE (16DTK20F1020)
// TRAFFIC LIGHT
// 7/3/2022
#define LED_RED 14
#define LED_YELLOW 12
#define LED_GREEN 13
#define PED_GREEN_LIGHT 15
#define PED_RED_LIGHT 2
#define BUTTON_PIN 27
//The below are variables, which can be changed
int button_state = 0;
//Variable for reading the button status
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LED_RED, OUTPUT);
pinMode(LED_YELLOW, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(PED_GREEN_LIGHT, OUTPUT);
pinMode(PED_RED_LIGHT, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop(){
changeLights();
delay(15000);
//read the state of the button value
button_state = digitalRead(BUTTON_PIN);
//control LED according to the state of button
if (button_state == LOW)//if button is presssed
}
}
void changeLights(){
// green on,
digitalWrite(LED_GREEN, HIGH);
delay(500);
// green off, yellow on
digitalWrite(LED_GREEN, LOW); // 3 second off green light
digitalWrite(LED_YELLOW, HIGH); // yellow light on in 3s coming
delay(3000);
// turn off yellow, then turn red on for 5 seconds
digitalWrite(LED_YELLOW, LOW);
digitalWrite(LED_RED, HIGH);
delay(4000);
// red and yellow on for 2 seconds (red is already on though)
digitalWrite(LED_YELLOW, HIGH);
delay(2000);
// turn off red and yellow, then turn on green
digitalWrite(LED_YELLOW, LOW);
digitalWrite(LED_RED, LOW);
digitalWrite(LED_GREEN, HIGH);
delay(3000);
}