Stepping up from traffic lights last time, I decided this time to have a crack at making a Pelican crossing.

A Pelican crossing is a pedestrian crossing consisting of two sets of traffic lights, a button, and a signal to indicate that it is safe for pedestrians to cross. The sequence that the lights follow is slightly more complex than before:

  • Initially, the traffic signal lights are green and the pedestrian “red man” is on red.
  • When the button is pressed, the traffic signal lights cycle to red.
  • Once the traffic signals are red, the pedestrian signal is set to green and a buzzer sounds for a period of time.
  • When the buzzer has finished beeping, the traffic signals are set on flashing amber and the pedestrian green signal also flashes.
  • After a little while, the traffic signal is reset to green and the pedestrian signal to red.

The Circuit

The circuit for this is slightly more complex.

The traffic signals are now linked, so each red, amber, and green light can be linked in parallel. We introduce two new lights for the pedestrian signal, together with a buzzer.

experiment 2 - traffic lights crossing

I know there are two red/green men in real life, but this is a slight simplification. Just connect red/green leds in parallel for the second set, as we did for the main linked traffic signals.

The Software

The code is fairly similar to before, we extend the class to control three additional outputs – the red and green man and a buzzer, as well as to listen to a given input button press.

The main loop waits for a button press and when detected it toggles the lights, sounds the buzzer, then toggles the lights back.

Here it is in action…


experiment 2 - traffic lights In the last experiment I wired up LEDs to each one of the PiFace’s outputs and cycled through them. In this one, I decided to try a slightly more “real world” application, and build a set of traffic lights.

Since I live in the UK, these are the UK three light traffic lights (red/amber/green) and follow the UK light sequence – RED, RED/AMBER, GREEN, GREEN, AMBER, RED.

The Circuit

The circuit here is very similar to the one used for the previous experiment, but will only use six of the available eight control outputs. Each light contains a set of three LEDs connected to one of the pins of the PiFace’s output interface, one red, one amber and one green.

See the attached diagram.

The Software

The code for this experiment is where the extra complexity resides, since we must drive each light in the correct sequence and obeying certain rules:

  • The lights must transition in the correct, UK, sequence, i.e. RED, RED/AMBER, GREEN, and then GREEN, AMBER, RED.
  • For traffic safety, the green light must transition to red before the red light transitions to green.

To avoid repeating myself, I created a simple class to drive the lights.

Each class is initialised with the pin number of each light, and an initial status. The Toggle method will transition the light; RED, RED/AMBER, GREEN if status is RED, and GREEN, AMBER, RED if status is GREEN.

The main loop of the program waits for a period of time, then toggles the lights, starting with the green one.

Here we have it in action…