Pelican crossing - developing the model - 3
Here is our description:
Comment | Red light | Yellow light | Green light | Wait light | Red man | Green man | Buzzer |
Cars going normally along road. | Off | Off | On | Off | On | Off | Off |
The button is pressed and you wait. | Off | Off | On | On | On | Off | Off |
Eventually, the lights start to change. | Off | On (2 secs) | Off | On | On | Off | Off |
Now you can start to cross. | On | Off | Off | Off | Off | On (flashes) | Beeps |
After 5 seconds, the lights start to change. | Off | On (flashes) | Off | Off | Off | On (flashes) | Off |
Cars going normally along road. | Off | Off | On | Off | On | Off | Off |
And we have our code for the first position, where cars are running normally along the road:
We need to write the code for the rest of the steps. There are a couple of tricky parts. One, is how to make the lights flash. The other, is how to get a beeping sound. Therefore, we are going to conveniently ignore those until later. So, until later,:
when a light is flashing, we'll just turn it on.
when the buzzer is beeping, we just won't have a buzzer yet!
Sometimes, parts of a model are hard. We mustn't let that stop us producing a model, though. We must simplify the model, move on and make some progress, then come back and sort out the difficulties. That's the technique we are using here.
Q1. Get the following code working. When you have this code working, your job is to finish the whole cycle off. Remember, for the moment, ignore flashing lights (just turn the light on) and the buzzer (don't have one).
You will notice that I have added lots of comments by using the hash key. The comments are in red. The program ignores these as they are for the programmer, to help them understand the code. Ignore adding comments at your peril! Your code and the logic will be very difficult to follow or to find errors in if you miss out comments.
At the end of this task, all of your Pelican crossing should be modelled. Make sure you fully test this, so that the cars are running again at the end of the program and all the lights are in the correct state. You may need to rearrange the windows on your screen so you can press the ENTER key in Python half way through the program and then see the graphics window changing again. The flashing lights and the buzzer will be the next task.