Building a simple Pong clone on the Raspberry Pi, using an LED matrix and gyroscope
UTS Prototyping Physical Interaction — Spring 2017
Develop an element of an interactive system using one or more sensors.
What I’ve developed: a UI element (rendered to an LED matrix) that moves left and right according to the orientation of the Pi. I developed a Pong clone for the Pi in which this element was employed as a paddle.
Rationale: I wanted to develop something fun and personally challenging to implement. The LED matrix provides a retro aesthetic, which you wouldn’t get otherwise on a smartphone screen. Conversely, the gyroscope is a relatively modern addition in the design of technology (your gameboy didn’t have one), and makes interaction much more intuitive. Given these two components, it was evident that recreating something akin to Pong would be an interesting and exemplary interactive system.
Types of contexts
This element tracks the orientation of the Raspberry Pi (as an angle of 360 degrees) but notably only uses a smaller range of 52 degrees.
The rationale for this is because the display is needed to convey information, the range for tilting is restricted to what keeps it in view.
Some potential contexts this could be used in:
- Presenting the user with a binary choice to make, and use the tilt to determine yes (tilt left) or no (tilt right), where the LED display provides visual feedback on the outcome.
- In combination with another element (such as a button) as a control with a spectrum of values e.g. using it as a volume slider
- With an LED display to provide an intuitive gameplay element (described below)
Demo — Pong
Things you will need:
- Raspberry Pi and its OS on the microSD card
- Raspberry Pi Sense HAT
- A method to connect to the Pi to upload and run code (HDMI+keyboard, Ehternet+SSH, etc.)
How to use it:
- Open a terminal to your Pi
- Copy and paste my code below, and hit Ctrl+O to save and exit.
Turn the board from side to side to move your paddle. The ball will bounce around. When it hits the paddle it will bounce back.