Microbit
Beginner
30 mins
100 points
What you need:
  • Chromebook/Laptop/PC
  • Microbit
  • Traffic Lights Kit

Microbit Traffic Lights

In this lesson we program our traffic lights to go through a sequence.

1 - Create a new Microbit project

Go to the makecode.com website and create a new Microbit project.

2 - Add the Stopbit extension

There are custom code blocks that we use to program our traffic lights kit. To add them to our toolbox we need to add the "stopbit" extension.

Search for the "stopbit" extension and then click on the traffic lights kit picture.

This will add the "Kitronik STOP:bit" category of code blocks to your toolbox.



3 - Test all the lights

First let's test that all the lights work on your traffic lights. Add the following code and then send it to your Microbit.

After you have sent the code to your Microbit, test that each light works by pressing the A, B and A+B buttons. If any of the lights are flickering then make sure that the screws are tight.

4 - 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 5 seconds
  2. show yellow light for 1 seconds
  3. show red light for 2 seconds

5 - Program the sequence using on/off

Delete the code you have created already as we no longer need it.

There are two different ways we can display the lights on the traffic lights. The first way is just by setting each light to either on or off.

Add the following code to make the traffic lights forever go through the sequence. Once you've added the code, download and send it to your Microbit.

Check that the lights are displaying in the right sequence.

  1. Green for 5 seconds
  2. Yellow for 1 second
  3. Red for 2 seconds

Join our club 😃

To view the remaining 1 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.
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more