Question: Lab Task Session 1 - Input and Output i . Traffic Lights: To develop a C program to simulate the control of traffic lights. Three

Lab Task Session 1- Input and Output
i. Traffic Lights:
To develop a C program to simulate the control of traffic lights. Three output ports are used to periodically control the Green, Yellow, and Red LEDs in the following pattern:
Green LED is turned ON for 5 seconds;
Yellow LED flicker for three times (i.e., ON 0.5s and OFF 0.5s, an repeat for three times);
Red LED is turned ON for 5 seconds;
Caution: DO NOT forget to use resistors because directly connecting an LED may result in a large current burning down the LED.
ii. Main Switch to Control the Traffic Lights:
Add a button switch to control all three traffic lights. When the button switch is pressed down, all traffic lights are turned off. When the button switch is released, the traffic lights return to their normal working state. A pull-up or pull-down resistor may be used depending on your own code.
rig. 4 ivialn swilcn
I completed the traffic lights part
but the main switch to control part i have no ideal
below is traffic light program
int REDPIN =13;
int YELLOWPIN =12;
int GREENPIN =11;
// set the pins tr output pins ysong pinMode.
void setup (0){
pinMode (REDPIN,OUTPUT);
pinMode (YELLOWPIN,OUTPUT):
pinMode (GREENPIN,OUTPUT);
}
void loop (){
djgitalWrite (REDPIN,HIGH); // Green LED is turned ON for 5 seconds
digitalWrite (YELLOWPIN,LOW);
digitalWrite (GREENPIN,LOW);
delay (5000);
digitalWrite (GREENPIN, LOW);/Nellow LED flicker for three times
delay (500);
digitalWrite (YELLOWPIN,HIGH):
delay (500);
digitalWrite (YELLOWPIN,LOW):
delay (500) :
digitalWrite, (YELLOWPIN,HIGH):
delay (500);
digitalWrite (YELLOWPIN,LOW):
delay (500);
digitalWrite (YELLOWPIN,HIGH);
delay (500);
digitalWrite (YELLOWPIN,LOW):
delay (500) :
digitalWrite (REDPIN,LOW);//Red LED is turned ON for 5 seconds
digitalWrite (YELLOWPIN,LOW);
digitalWrite (GREENPIN,HIGH):
delay (5000);
}
 Lab Task Session 1- Input and Output i. Traffic Lights: To

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!