• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.


Reader Jay Final Project

Page history last edited by Jay Reader 5 years, 1 month ago


Arduino Pong!


Design POV:


I knew from the beginning of the class that I wanted to pivot from the MP3 player and make a game console. Initially I had  wanted to make a device that would feed input to an emulator, to mimick a gameboy, but over time I realized that I really just wanted to make a device that I could use WITH my friends, instead of just showing it TO them. As such, I doubled back, and decided to go retro: Atari-style pong. For me, beyond the practicality of making a pong console (we actually like playing with it!), the fact that the code is manageable and can be done in-person, and natively in the arduino environment, made this project much more satisfying and a much better learning experience. This paves a path toward more complex 8-bit games, such as galaga and space invaders, which can be programmed in a similar fashion.








Arduino DUE (http://www.amazon.com/Arduino-A000062-Due/dp/B00A6C3JN2/   http://arduino.cc/en/Main/arduinoBoardDue)

100 Ohm resistor

2x 82 Ohm resistors

2 10k Ohm potentiometers

Simple SPST button, such as: http://www.jameco.com/1/1/9356-30-3-switches-push-button-spst-no-1a-black-actuator-back-panel-mount.html

8 Ohm speaker (simple setup, can use alternate if desired)

75 Ohm resistor (or alternate depending on speaker used)


VGA cable




I used a previous lab as reference for wiring the VGA output (as well as its original source). This will support the VGA library as referenced below, which will allow for functions such as drawRect() and drawEllipse().


Specifically, since pong is a monochrome game, we can use the monochrome output for the VGA, which requires only 3 resistors.

See below:


The photo is from http://stimmer.github.io/DueVGA/breadboard.html 

In this setup, the VGA is wired for RGB color mode. Since we only need monochrome, pins RGB can just connect in parallel to the MOSI pin.

As such we only need 2 82 Ohm resistors for Hsync and Vsync (pins 42/43) and a 100 Ohm resistor for the RGB.

Due VGA library breadboard circuit

Due VGA socket wiring


For the other inputs, I used 2 10K potentiometers (analog works well for this project). The wiring can be seen here, as referenced from a previous EE47 lab (Summer 2015 Lab 3):


Be sure to use the 3.3V output on the DUE, not the 5V output, since the DUE is a 3.3V board, and the pins are calibrated for that .



Similarly, you can use this reference for setting up the button circuit, which will trigger a high value when off (Summer 2015 Lab 2):


IMPORTANT: DO NOT USE 5V for Vcc, use 3.3V or you will burn out the board. The input can be any digital pin.


Finally, I used this reference for a speaker circuit, which I then used to play simple tones (Summer 2015 Lab 3):


Again, any digital pin works as long as the code supports it.

Breadboard with simple POT's used - sorry for the messy wiring! (notice that the 3 blue wires going into the VGA - the RGB inputs, are all run through 1 resistor into the SPI on the board.)



Final wiring (not a great photo, but you can see that there are 4 main areas - VGA, potentiometers, speaker, and button:




A copy of my code can be found here: http://pastebin.com/9MTp0yP5

Be sure to add a tab with the pitches.h page if you use those variables. (just like the toneMelody example)


With regard to tones, the DUE does not support the standard tone library, so I referenced code from here to generate the square waves and produce sound: http://forum.arduino.cc/index.php/topic,136500.0.html


As for the game, the setup initiates a loop that waits for a button press, which then changes the state of the loop such that it plays the game. The way this works with the VGA then is that the VGA.h library (found here: http://forum.arduino.cc/index.php?topic=150517.0) creates a screen of resolution 640x480, or whatever you spec up to 800x600. Then, using an absolute coordinate system (origin is top left corner of the screen), each loop clears the screen and redraws the rectangles and ellipses, etc. using updated input parameters. All of these functions are outlined in the VGA library's README.txt file. A collision checker function, and a ball location updater is then called.


In this case, only the top/bottom of each bar is checked for paddle collisions (if the bottom of the ball and top of the lower bar's coordinates are the same, there is a collision and we flip the ball direction, etc.), but this code can be built out further if desired.



Some good checkpoints if writing your own code:

Get the VGA library to work, and try some of the included examples.

Get comfortable with the drawing functions - draw some shapes and manipulate their location!

Get the paddles drawn in a loop that responds to the POT input (you'll have to scale input from 1023!)

Get the ball drawn and have it update its position over time

Build out the collisions, and keep track of score!

Add the reset/any menus you'd like


State Diagram:


Comments (1)

xyyue@... said

at 12:39 pm on Aug 18, 2015

Hi Jay,

Well done!! We love your idea and this is really a good project! We tried your device last Saturday and it's great! The idea is pretty nice as it's really working and even remind us of our childhood!

The Verplank and the State Diagrams are pretty clear and impressive. Also, the lab report is pretty detailed, and the pictures of the device could really help us understand your design much better!

We also like it that you also provide the code to help us better understand the implementation. We wish that you could write more comments in the code to make it more readable.

Well done during the summer and good luck!!!!!!

You don't have permission to comment on this page.