In this project, we continue the development of our Simon Says pattern matching game by adding the LEDs to our circuit.

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. Once this is complete, we will have the working circuit for our game, and we can start writing the code to bring it all together.

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

## 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 , 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.

## 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:

## Wire Your Third LED Using a GPIO Output.

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

Here is what your breadboard should look like:

## 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 wire 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.

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):

from rstem.gpio import Output import time my_leds = [Output(4), Output(18), Output(24), Output(27)] for led in my_leds: led.on() time.sleep(.6) led.off() time.sleep(.2)

If you run this code, you should see each LED flash briefly.