Gadgetboard application: Stoplight Controller

Here's a very simple stoplight controller. This could be useful for model train sets, or perhaps even as the basis for a real traffic signal. I didn't have any yellow LEDs, so I had to use blue instead. The LEDs shown are high brightness devices packaged in sockets, designed to run on 12Vdc. I soldered leads to them and tinned the other ends so they don't fray when I put them in the screw terminals. Here's the digikey product page. Since the units have built-in limiting resistors, I don't have to worry about adding them to keep the LEDs from drinking too much current and burning out. I just connect each one to its output and the adjacent power or ground pin, making sure to observe the polarity of the LED.

The code is very straightforward. It just sits in a loop, cycling between stoplight states. I added a safety check function which is always called before the outputs are set to ensure that the code isn't asking for an unsafe light configuration (for example, having both lights green at once).

This time, rather than overriding the command-line handler entirely, I added a command which tells the board to go into stoplight mode. Then I even added a check at the end of each stoplight cycle which reads input 1 and breaks out if it's high. That way I can use a little piece of wire to tie input 1 to +5v if I want to break out of the stoplight code and go back to command line mode for further prototyping.

Here's the source code for the stop light controller.

And here's a video of the code in action:

Wouldn't it be great if traffic systems used Free software and were transparent to the public? It could lower costs for developing countries, and give programmers a chance to improve traffic flow, potentially saving millions of dollars worth of time and fuel.