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 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 seconds;
Yellow LED flicker for three times ie ON and OFF an repeat for three times;
Red LED is turned ON for 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 pullup or pulldown resistor may be used depending on your own code.
rig. 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 ;
int YELLOWPIN ;
int GREENPIN ;
set the pins tr output pins ysong pinMode.
void setup
pinMode REDPINOUTPUT;
pinMode YELLOWPINOUTPUT:
pinMode GREENPINOUTPUT;
void loop
djgitalWrite REDPINHIGH; Green LED is turned ON for seconds
digitalWrite YELLOWPINLOW;
digitalWrite GREENPINLOW;
delay ;
digitalWrite GREENPIN LOW;Nellow LED flicker for three times
delay ;
digitalWrite YELLOWPINHIGH:
delay ;
digitalWrite YELLOWPINLOW:
delay :
digitalWrite, YELLOWPINHIGH:
delay ;
digitalWrite YELLOWPINLOW:
delay ;
digitalWrite YELLOWPINHIGH;
delay ;
digitalWrite YELLOWPINLOW:
delay :
digitalWrite REDPINLOW;Red LED is turned ON for seconds
digitalWrite YELLOWPINLOW;
digitalWrite GREENPINHIGH:
delay ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
