Each time we perform an exercise we will create functions which do things for us. In this case I now have a function which can be used to get the state of a user input. It will return (after a short interval) with the "proper" state of the input.

On the right we have the example code for a fully working torch with a debounced switch. The code is similar to our previous example, but we now call the key function to "debounce" the inputs each time. If you run program 2.4 you should find that the torch operation is now quite solid.

You will find the key function appearing in other programs which need to read the state of an input key.