Introduction: Raspberry Pi GPIO Game

You will need...
-Raspberry pi model b+ with raspbian and Python 2(which should come with raspbian)
-HDMI monitor and cable
-3 tactile push switches
-Breadboard(you can get by without it be connecting straight to the buttons, but this also works as a stand for the buttons)
-male to female wires (or, in my case, male to males with a ribbon cable)
-Power supply

Step 1: Setup

You should know how to connect your power supply and monitor already

To Start, we will set up the three Push Switches.
If you aren't familiar with the GPIO pins, I found that this forum had a good diagram for each of the pins:
https://www.raspberrypi.org/forums/viewtopic.php?f...

Take your Push Switches and place them in your breadboard as shown in the picture. Connect one side of each button to a 'ground' pin. Then connect the other Side of your left button to GPIO17. Note: that isn't the same as pin 17.
Next connect the middle button to GPIO21, then the right button to GPIO18.

You can use different GPIOs but be sure to set up the correct pin in your code.

Step 2: Writing the Code

Feel free to use your own code if you like, but I will provide a simple program that I wrote that uses pygame with simple shapes and text, no images.

Note: to run the code, you need to use a lx terminal session. Enter the command:

sudo python filename.py

Step 3: Run at Boot(optional)

For convenience, you can set it to run the program at boot. There are multiple ways to do this. A very easy way that I use is the Crontab command.
Open an LX Terminal session and enter the command:
crontab -e
This should open a nano editor. Scroll all the way to the bottom the following command to the very bottom:
@reboot sudo python filename.py

Now, if you reboot your Raspberry Pi, it should run normally until it reaches the point where, normally, you would log in. Depending on the file, it may take a second to load, but the game should pop up on the screen. When you quit the game, it will close that window and go back to the login. It should run normally from there.

Comments

author
Slapshot135 made it! (author)2015-04-21

If anybody tries out the code, let me know what you think. I know that the graphics and stuff are kinda bad, but if you have any ideas on what I should add, let me know

author
nfarrow made it! (author)nfarrow2015-10-22

You should turn it into some kind of Mindflex Game

GPIO.png
author
Slapshot135 made it! (author)2015-04-22

Ive updated the code with a few modifications that I made to it so its not quite as bad

author
Slapshot135 made it! (author)2015-04-20

It's a really simple game where you control a block that can move left and right and you have to shoot down targets that move across the screen

author
amberrayh made it! (author)2015-04-20

Thanks for sharing! What is the game like?