Scratch
Beginner
45 mins
180 points
What you need:
  • Computer/laptop

Traffic Light Sequence

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!

1 - Introduction

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.


2 - Create a new Scratch project

Go to the Scratch website, create a new project and delete the cat sprite.

https://scratch.mit.edu

3 - Upload the Traffic Lights sprite

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.

4 - Duplicate the sprite

We need 2 sets of traffic lights so follow these steps to create a copy of the traffic lights sprite:

  1. First drag the traffic lights to the left hand side of the stage area.
  2. Right click on the traffic lights sprite in the sprite list.
  3. Click on 'duplicate' and it will create a copy of it so you now should have 2 traffic light sprites.

5 - What is a sequence?

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:

  1. put on her sock
  2. put on her shoe
  3. tie her laces

For our traffic lights we are going to program them to go through this sequence:

  1. show green light for 10 seconds
  2. show orange light for 3 seconds
  3. show red light for 1 seconds

Join our club 😃

To view the remaining 8 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more