Using Block commands it is possible to control up to six outputs. This experiment will use all six to create a traffic light and pedestrian crossing demonstration. Five of the outputs will be used to drive LEDs, three of which will be used for the traffic light and two will be used for the stop and go indicators on the pedestrian crossing. The remaining output will be used to drive the piezo buzzer. This will all be controlled by a relatively simple sequence of Block commands.
First of all the traffic light LEDs default to ‘green’ and the pedestrian crossing LEDs default to ‘red’. When button A is pressed on the BBC microbit the traffic light LEDs go from ‘green’ to ‘amber’ to ‘red’. The pedestrian LEDs then change from ‘red’ to ‘green’ indicating that it is safe to cross, during which the buzzer beeps. After eight beeps the pedestrian LEDs change back to ‘red’ and the traffic lights go through the ‘red’ to ‘red + amber’ to ‘green’ sequence. This is now back at the original starting state.
To access the required code click here.