Traffic Lights

Sequencing

The order in which actions take place is very important when creating an algorithm. When making a cup of tea, you don't pour the water into the cup until after it has boiled!

Traffic lights are programmed to follow a set sequence of changes (you may have seen the green box near junctions that has the embedded computer that controls the lights).

Take a look at the traffic lights, what are the 4 phases of the sequence?

At each phase, which lights are on, and how long are they on for?

An introduction to the Kitronic STOP:bit

How to program the Kitronic STOP:bit

Challenges

Simple Traffic Light Sequence

Program the STOP:bit so that it repeatedly goes through the normal traffic light sequence.

Pelican Crossing

Program the STOP:bit so that:

  • When it starts the light is green and the LEDs on the micro:bit show a wait image.

  • When the A button is pressed:

      • There is a short pause

      • The lights change to red (via ready to stop)

      • The LEDs on the micro:bit changes to walk

      • There is a longer pause

      • The LEDs on the micro:bit changes to wait

      • The lights change to green (via ready to go)

Extend the program so that the amber light and the walk light flash 5 times before the LED's changes back to wait and the lights change to green.

Key Words

Sequence

The particular order that actions take place, one following the other.

Algorithm

A set of instruction that can be followed in order to complete a task

Program

A stored set of instructions for a computer to follow that completes a task.

Subroutine

A small sequence of instructions that complete a task. They can be 'called' repeatedly in a program, allowing code to be re-used.