SIMON 1

In our previous project, we discussed the pseudo-code for our pattern-matching game.  But, before we start writing the code, we're going to build the electronics for the game, and write some test code to ensure that what we've built works as we expect it to. 

The game will require four different colored buttons (wired as GPIO Inputs) and four LEDs (wired as GPIO Outputs).  We'll also need four resistors -- one for each LED we'll be wiring.  We will essentially be replicating the circuit designs that we learned in previous projects, but on a larger scale.  

Note:  Because the fully-built circuit will use up a lot of breadboard space and require a lot of wires, we highly recommend starting this project with an empty breadboard, and implementing the circuit in a way that's similar to the diagrams we provide.  Also, you'll notice that we wire the buttons, LEDs and other components in a specific pattern (a square or diamond shape) -- this will help make our game more playable when it's complete.

In this project, we'll wire up the four buttons and write some code to verify they are working.  In the next project, we'll wire up the four LEDs and write some code to verify they are working.  At that point, the circuit is complete, and we'll spend several additional projects building the code to make the game fully operating.  Take your time, follow along, and pretty soon, you'll playing an electronic game that YOU built and programmed!

Hardware Implementation

For this project, we're going to recommend that you clear your breadboard.  While half the breadboard should be sufficient space, starting with a clean board can help avoid confusion in your wiring.  We also suggest trying to build this project on just the left-hand side of breadboard -- by doing this, you should be able to put some upcoming projects on the other side of the breadboard, which is nice so that you won't have to tear down this project to make room for the other.

Hardware Step #1:  Provide Power to Both Power Rails

Because this circuit is going to be a bit larger than our previous circuits, and because we're going to want to organize our components in a way that we can actually use them later, we're going to make both power rails (the red and blue strips on either side of the board) available.  As we've done previously, we make one set of power rails functional by running wires from one of the 3.3V pins and one of the GND pins on the connector board to the red and blue rails.

To get power and ground to the other set of rails, we then run wires from one red rail to the other and from one blue rail to the other.

Here is what your breadboard should look like:

Hardware Step #2:  Wire Your First Button Using a GPIO Input

Now that we have power and ground on both sides of the board, we can start wiring our components.  We'll ultimately want four buttons and four LEDs arranged in a diamond pattern, so we start by wiring the first button towards the top of the breadboard.  If you recall from Using Buttons With GPIO, to wire a button to a GPIO, the circuit schematic should look as follows:


To implement that circuit on the breadboard, we wire one side of the button to ground and wire the other side of the button to a GPIO.  We're going to choose GPIO14 for our implementation; you're welcome to use a different GPIO, but if you do, keep in mind that you'll have to modify the code we provide to match your GPIO selection.

Here is what your breadboard should look like:

Hardware Step #3:  Wire Your Second Button Using a GPIO Input

We can now wire the second button similarly to the first.  Again, remember that we're looking to build a diamond pattern, so this button should be positioned appropriately.  For our circuit, we're going to attach the second button to GPIO15.

Here is what your breadboard should look like:

You'll notice that we used two small jumper wires to attache the second button to ground.  You could certainly use one longer wire to attach the button, but we've found that by using the small wires, you won't have the larger wires getting in the way while you're trying to use the buttons to play your game.  Not to mention, the whole circuit will look cleaner by using the small jumpers as much as possible.

Hardware Step #4:  Wire Your Third Button Using a GPIO Input

We can now wire the third button just like the first two.  For this button, we've chosen to use GPIO22.

Here is what your breadboard should look like:

Hardware Step #5:  Wire Your Fourth Button Using a GPIO Input

It's time to wire our fourth and final button in our circuit.  For this last button, we've chosen to use GPIO17.

Here is what your breadboard should look like with all the buttons wired:

Good job!  You should now have four buttons wired on your breadboard.  Before we wire up any more components, let's write some code to test that the buttons are wired correctly and are operating as we expect...


Programming Implementation

Now that we have our buttons wired, we're going to write some test code to verify that they are each working correctly.  In our Many Buttons project, we learned how to generate a list of buttons and take input from each of them -- we're going to do the same in our test code below.

The GPIOs we use for our buttons are:  GPIO14 (top button), GPIO15 (right button), GPIO17 (bottom button), GPIO22 (left button).  In our button list, we'll initialize the buttons in that order, so that we refer to button #1 as the top button, button #2 as the right button and so forth.  

Here is what that code will look like:



If you run this code, you should see the status of each button being updated in the Output Window.

prev| next