Traffic Lights and States

This week we would be learning how to program a set of LEDs to represent traffic lights at a junction. We programmed the different stages of light combinations using states. A state gives a specific set of instructions whilst in that state, allowing complex tasks to be broken down and done simply. A state can have a transition to any other states given a certain condition.

The states in our experiment could either be changed from a physical input (button press) or a timer or a combination of both.

Working with state machines is convenient as you can break down each state seperately and mistakes in each state don’t affect other parts of the program. Because of this it is usually easy to identify where the problems are during troubleshooting.

In this lab we were representing a set of traffic lights with coloured LEDs. The traffic lights operated by changing state when a button was pressed, changing from green to yellow to red using delays between states. after a set time, equivalent to a person crossing the road, the light would turn green again.

We decided from this experiment that we would rely heavily on states whilst developing our own robot.

Leave a comment