Wikijunior:Raspberry Pi/Raspberry Pi Simon Says Game

Simon Says (or just simply Simon) is an electronic board game where the object is to memorise the sequence of red, yellow, blue and green colours and then press the corresponding buttons in order.

Breadboard
The mini breadboard has a top and bottom section. All the points along each column in each section are joined, so we can make electrical connections.

You will need ×1 breadboard.

Light-Emitting Diode (LED)
The LED (Light-Emitting Diode) has a short leg and a long leg. If you feel around the rim, you'll also find a flat edge. The short leg and flat edge always connect to the negative (ground).

You will need ×4 LEDs: ×1 red, ×1 blue, ×1 green and ×1 yellow.

Resistor
The resistor can be connected any way around. We're using a 270 Ohm resistor but anything between 220–470 Ohms will work fine.

You will need ×4 resistors.

Momentary switch
The switch can be connected any way around. When pressed, it allows electricity to flow; when released, the electricity stops. This kind of push-button is known as a "momentary press-to-make switch".

You will need ×4 momentary switches.

Jumper wires
Jumper wires (also called DuPont wires) connect electronic components to the GPIO pins. You should also have two short and one long jumper wire (all "female to female" – holes at both ends).

You will need ×16 jumper wires.

Putting the breadboard together:


The Raspberry Pi has two ways of labelling the General Purpose Input-Output (GPIO) pins:


 * Board numbering – just starts from the bottom-left at 1, and works its way up and right, through to 40.
 * BCM numbering (Broadcom numbering) – is the way the Raspberry Pi's processor sees the pin connections.

Step 1: Connect the LEDs to the GPIO pins on the Raspberry Pi. You can use any combination of GPIO pins, but it is important to note that the LEDs must be connected to pins that support PWM (pulse-width modulation).

Step 2: Connect the buttons to the GPIO pins on the Raspberry Pi. You can use any combination of GPIO pins, but it is important to note that the buttons must be connected to pins that support input.

Write a Python program:
Step 3: Write a Python program to control the LEDs and buttons. The program should generate a random sequence of LEDs to light up, and then wait for the user to press the corresponding buttons in the correct sequence. If the user presses the buttons correctly, the program should advance to the next level. If the user presses the wrong button, the program should end the game.

Once you have written the Python program, you can save it as a file with a `.py` extension, such as `simon_says.py`. Then, you can run the program by typing the following command into a terminal window:

The game will start and the LEDs will light up in a random sequence. Press the corresponding buttons in the correct sequence to advance to the next level. If you press the wrong button, the game will end.

You can make the game more challenging by increasing the length of the sequences and by adding different types of actions, such as clapping your hands or stomping your feet. You can also add sound effects to the game using a buzzer or speaker.