Challenge: traffic lights
This challenge consists of a series of steps which start simple and get a lot harder. It tests what you have just learnt as well as asking you to think laterally to get the system to do what is required.
Stage 1
-
Set up a circuit with three LEDs, one red, one green and one orange. Don't forget the resistors.
-
Write a sketch which cycles through the LEDs in the standard UK sequence (green - orange - red - read and orange - green)
-
Check your work and make any necessary changes
Stage 2
-
Modify your circuit to include a pedestrian request button.
-
Modify the sketch so that the lights stay green until the button is pressed. Then it goes through the standard sequence
-
Check and correct
Stage 3
-
Modify the sketch so that the lights stay green for at least 10 seconds. That is to say, if the button is pressed after the lights have turned green, they do not go back to red immediately. There is a delay until the minimum green time has expired
-
Check and correct
Stage 4 (Advanced)
-
Modify your circuit so that there are two sets of traffic lights as if they were located at a junction. the sequences must correspond so that when the lights are green in one direction, they are red in the other.
-
Modify the sketch so that the lights alternate between green and red with appropriate transitions between the two main states.
-
Check and correct
Stage 5 (Even more advanced)
-
Modify the circuit again to include a pedestrian request button. We could include two, but they would have an identical effect.
-
Modify the sketch so that the lights both go to red after the button is pressed. You must also maintain the rule that says that a light once green must stay green for at least 10 seconds.
-
Check and correct