SIMON 2
In this project, we continue the development of our Simon-like pattern matching game by adding the LEDs to our circuit.
Speaker & Audio Cable
I/O (Input/Output) RaspberrySTEM Cell
Having issues? Check out the Troubleshooting Guide.

In the previous project, we wired up and tested the four buttons we'll be using for our pattern-matching game. Now it's time to add four LEDs to the circuit from our last project and test those.

Hardware Implementation

We're going to start with the breadboard setup from the previous project.

Hardware Step #1: Wire Your First LED Using a GPIO Output

For this game that we're building, we'll have four different colored LEDs, and each LED will be associated with a particular button. For that reason, we're going to want to wire our LEDs in locations where we can easily tell which button each LED is associated with. While you're welcome to wire the buttons in any locations you choose, our instructions below will put each LED as close as possible to its button.

If you recall from GPIO AS OUTPUTS (CONTROLLING LEDS), to wire an LED to a GPIO, the circuit schematic should look as follows:

We've chosen GPIO4 for our first LED. As for LED color, it shouldn't matter which LED color goes with which button, so we've arbitrarily chosen orange for this one.

Here is what your breadboard should look like:

Keep in mind that you're going to want to ensure that neither leg of the LED sits in the same connect strip as a button or another LED.

Hardware Step #2: Wire Your Second LED Using a GPIO Output

We can now wire our second LED. We've chosen GPIO18 for this LED and are using a yellow LED.

Here is what your breadboard should look like:

Hardware Step #3: Wire Your Third LED Using a GPIO Output

Time to wire our third LED to the bottom button, like just the previous two. We've chosen GPIO24 for this LED and are using a red LED.

Hardware Step #4: Wire Your Fourth LED Using a GPIO Output

It's time to wire our final LED. We've chosen GPIO27 for this LED and are using a green LED.

Here is what your breadboard should look like:

You'll notice that we chose to use an extra jumper to attach the LED to the GPIO -- again, we're going to want to be able to press each of the buttons in our circuit, so keeping the wires off to the sides as much as possible is highly recommended.

Congratulations...you've just finished the wiring for your first game!

Before we move on to start implementing the game software, we're going to write some code to verify that the LEDs are all wired correctly and are working properly. Like with our button test code, our LED test code is going to have two sections -- the first will import the functions we're going to need for the rest of the code and the second will test each of the LEDs.

Programming Implementation

To test our LEDs, we'll create a list of LEDs and cycle through turning each of them on and off.

Here's what this import code should look like (this probably looks familiar from earlier GPIO projects):

home | prev | next