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.