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…


It was recently revealed that the NSA and FBI have been using the US Patriot act to conduct blanket, unwarranted, surveillance of US citizens (and anyone who happens to talk to a US citizen), and of course comes as no surprise. The fact that major companies, Google, Verizon, Apple, to name but a few, were complicit in this, is very disappointing.

In the UK, the security services already track your phone calls, RIPA makes it a criminal offence to refuse to decrypt data (or what they believe is encrypted data) on the government’s request, and with plans to re-introduce universal internet surveillance (shamelessly capitalising on the tragic murder in south London of a young man, re-branded as “Terrorism”), we are taking the lead in creating the “Cradle to Grave” Surveillance State.

History shows that the greatest threat to an individual’s liberty comes from the state itself, rather than some foreign actor. My good friend Ben Werdmuller recently coined a new “Second Amendment”, which I thoroughly agree with:

Privacy being necessary to the sanctity of a free state, the right of the people to own and encrypt data shall not be infringed.

Of course, it is easier said than done. You can’t trust cloud based services to protect you; Apple, Google, Twitter, Facebook, your phone company and ISP are all complicit.

Wider use of encryption would be a start, but that’s hard to do in isolation. Email encryption is a microcosm of the problem; I’ve had a public key available for over a decade, but the grand total of encrypted emails I’ve received can be counted on the fingers of one hand. This is not because encryption or key management is necessarily complicated, it’s just that there is no motivation for me to use it if nobody else is as well.

It is useless in isolation.

Newer technologies fare better, without the need to carry too much legacy baggage, they can afford to switch on encryption from the get-go. Many, especially IM clients, have another advantage in that they are synchronous, and so could do content negotiation ahead of time. So, perhaps a mail client/webmail client with Webfinger support, and wider adoption of that?

Might help.

However, I think the biggest issue is that society at large tolerates the state doing this sort of thing. Perhaps “We the people” should start presenting a more unified opposition.

So, a few weeks ago I got a PiFace for my Raspberry Pi.

The PiFace is a clip on extension board for the Raspberry Pi which, together with the free library software, makes it super easy to control various real-world inputs and outputs – turning things on and off, and sensing whether switches have been pressed.

Pretty cool, but unfortunately due to my work load, and an ever growing to-do list, I had so far not had the time to play with it at all. However, a recent sports injury forced me to stay at home for a few days, and since I couldn’t really move (or indeed, put on my own socks), I decided to use this as an opportunity to play.

My first bit of tinkering was to see if I could wire up and take advantage of the 8 software controllable outputs exposed by the PiFace. These outputs consist of 9 connectors, the first of which is a 5 volt power line, and the other 8 being the ends of an open collector.

The Circuit

I am not an electrical engineer, so this is all brand new ground for me, and that is enough of a reason for me to find it all terribly exciting. These first bits of hardware hacking giving me the same thrill of figuring something out and getting something to work as when I wrote my first software programs all those years ago!

Anyway, the circuit is a simple one, and consisted of a breadboard with 8 leds connected in parallel with the 5 volt power rail on one side and the open collector terminal on the other. The back of the packet my LEDs in also noted that a resistor of 330 ohm should be used in series with the led when connected to a 5 volt power supply in order to avoid burning them out.

Experiment1

The Software

As a proof of concept, I wrote a bit of software to cycle through and turn each light on for a second, before turning it off and turning the next one on. Nothing too fancy right now!

The Finished Article

So, here’s my first experiment in action…


Like I said, I’m not an electrical engineer so this is hardly the Starship Enterprise, but I learnt a lot!