In this lesson we're going to program two sets of traffic lights at a busy junction. They need to work together to make sure none of the cars crash into each other!
In the picture there are 2 roads with a set of traffic lights for each road. The traffic lights are set up to never be green at the same time, otherwise the cars would crash.
In this project we're going to program 2 sets of traffic lights. We're going to program them to go through a sequence, green, then orange, then red and we're also going to get them to communicate with each other so that while one set of traffic lights is going through it's sequence, the other set is showing red and waiting it's turn.
Go to the Scratch website, create a new project and delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
There is a traffic lights sprite file included with this step called "traffic lights.sprite3". Download it to your computer by right clicking on it and clicking "Save Link As...". Then once you've saved it to your computer, upload it into your Scratch project.
This sprite has 3 costumes. One each for showing green, orange and red.
You can upload images and sprite files into your project. To upload a sprite follow these steps:
The new sprite will upload into your project and appear in the stage area.
We need 2 sets of traffic lights so follow these steps to create a copy of the traffic lights sprite:
We are going to program the traffic lights to show the lights in a sequence. In coding, a 'sequence' is the order in which instructions happen. For example if you were programming a robot to put on her shoe, the sequence would be:
For our traffic lights we are going to program them to go through this sequence: