Welcome to our exciting project! Today, we are going to program a set of traffic lights to display the lights in the right order. But before we start, let's talk about what a sequence is.
A sequence is like a list of instructions that we follow in a specific order. Just like when we get ready for school, we first brush our teeth, then we get dressed, and finally, we have breakfast. In coding, a sequence is a set of instructions that a computer follows one after the other.
In our project, we will create a sequence for our traffic lights to change from red, to green, and then to orange. Are you ready to start? Let's go!
In this lesson we are going to program a set of traffic lights to display the lights in the right order.
Click on the link below to open a starter project that already has a traffic light sprite added to it.
The traffic lights sprite has 3 costumes, a red costume, an orange costume and a green costume.
Let's program the traffic light to show the red light for 5 seconds. Add the following code to the traffic light sprite.
when green flag clicked
switch costume to (red v)
wait (5) seconds
Now let's program the traffic light to show the green light for 10 seconds after the red light is finished. Add the following code blocks to the traffic light sprite.
when green flag clicked
switch costume to (red v)
wait (5) seconds // add them under here
switch costume to (green v)
wait (10) seconds
Now let's program the traffic light to show the orange light for 3 seconds after the green light is finished. Add the following code blocks to the traffic light sprite.
when green flag clicked
switch costume to (red v)
wait (5) seconds
switch costume to (green v)
wait (10) seconds // add them under here
switch costume to (orange v)
wait (3) seconds