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.
We're going to start with the breadboard setup from the previous project, and add the following...
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 it's button.
If you recall from General Purpose Input/Output, to wire an LED to a GPIO, the circuit schematic should look as follows:
Based on that, to implement the LED circuit on the breadboard, we wire one side of the LED to 3.3V power with a resistor in-between and wire the other side of the LED to a GPIO. 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 the neither leg of the LED sits in the same connect strip as button or another LED, as the components will need to act independently, and we don't want to inadvertently send (or receive) signals to a component while trying to control another component.
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 GPIO23 for this LED and are using a red LED.
Here is what your breadboard should look like:
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.
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: