Hardware Reference
In-Depth Information
THE GAME IN this chapter is just the thing to get going on your irst hardware project.
here does not seem to be an end to the sorts of things you can do with LEDs and switches.
All the projects I have ever worked on, even highly complex transmodulation systems con-
sisting of 8000+ components, have started with an engineer making an LED lash. By adding
a bit of imagination you can make something unique with LEDs, and this project is, as far as
I know, totally unique. It is a colour snap game.
I am sure that most children have played the card game snap in one form or other either with
special cards or a regular pack. he procedure is simple: he pack is divided into two, and the
cards are laid face up on the table by alternate players. When two of the same cards are
turned up the irst player to shout “SNAP!” wins all the cards, but if you shout “SNAP!” and
the cards do not match, your opponent gets them. he player to lose all his cards is the loser.
You can implement this as a hardware game in many ways, but the one I have chosen here is
to use a coloured light. he light lashes on and of, and each time it comes on, it is normally
a diferent colour from the last time. However, occasionally it will be the same colour as the
previous one, and that is the cue for the players to claim a snap by pushing a button. here
are no arguments over who pressed irst; the computer has split second timing. Also, at the
same time the computer shouts out, “SNAP!” in one of two voices, depending on which
player was fastest to press the button.
Implementing the Game
So how are you going to implement this game? You need two switches and a source of con-
trollable coloured light. You could use the push switches that are already on the PiFace board,
but to make a decent job of the project you will take them of the board into a separate box.
(For more information on setting up PiFace, see Chapter 9, “Test Your Reactions”.) For the
source of changing colour, you are going to use three LEDs. An LED, or light emitting diode, is
a cheap and easy-to-drive source of light, so most hardware projects have at least a few.
Moreover, LEDs come in a rich variety of colours. here is however a rather special form of
LED which is known as an RGB LED. Basically this is three LEDs in one package: red, green
and blue. Using these you can mix up an almost ininite number of colours. So to start of,
let's see how to drive an LED from the PiFace board.
The Theory
Unlike with a lashlight bulb, you can't connect an LED directly to a source of power. Well,
you can, but it will end up burning out. his is because LEDs have a special form of electrical
characteristic: hey are a nonlinear device. What this means is that unlike other components,
such as resistors, the current through LEDs is not directly proportional to the voltage across
them. hey have an efective resistance that switches sharply depending on the voltage
across them. Figure 8-1 shows the graph of voltage against current for a typical LED. You will
Search WWH ::




Custom Search