Our first light switch will be very simple. If I hold the button down, the light is on. If I release the button the light goes off.

Note this is just the same as if we had a push switch wired in series with the bulb so I am using a small computer to behave as a piece of wire!

The diagram shows the flow of our first program. The boxes contain actions and the diamond denotes a decision which is made as our program executes. The arrows show how the execution moves from one box to the next.

From this we can see that the program is repeatedly checking the state of the port and switching the light on or off depending on the state of it.

We actually construct the program in C by using an if condition to look at the port and place the whole thing in a while loop.

Sometimes it can be useful to draw out the sequence of actions a program should perform, particularly for the first few programs that you write.