Arduino Pong

Justin Alava

Patrick "PMONEY" Miazgowicz

Basic Description: Our project is a simulated game of ping pong. It resembles the arcade version of the game from the late 70's. To put it simply, the game is designed with two paddles on both sides that are controled manually and a ball that bounces around the edges. Whoever hits the ball more times will win the game.

Electronic Description: We ran a program through the arduino with a laptop as a power source to display a game of Pong on a television. We imported an arduino-tvout ( library to make it run it through an old NTSC T.V. Our circuit consists of 2 analog inputs to control the paddles, 2 digital outputs to display the game on the television, and the power that ran through positive and negative of the breadboard. We used alligator pins to connect the digital outputs to video cables which were input into the T.V.


#include <TVout.h> #include "pitches.h"//declare stuff TVout TV; unsigned char x,y; int xDir=1; int yDir=1; int leftPaddle; int rightPaddle; int leftPot=2; int rightPot=3; int scoreLeft=0; int scoreRight=0; void setup() { //set the ball x=5; y=11; TV.start_render(_NTSC); TV.print_str(12, 1, "Pong"); TV.select_font(_5X7); pinMode(leftPot, INPUT); pinMode(rightPot, INPUT); } void loop() { //clear screen TV.clear_screen(); //score TV.print_char(35,2, '0'+scoreLeft); TV.print_char(85,2, '0'+scoreRight); //ball TV.set_pixel(x,y,1); x=x+xDir; y=y+yDir; //bounce if hits right paddle if (x>118) { if(y>rightPaddle-2 && y<(rightPaddle+12)) { xDir=-xDir; } else { y=leftPaddle+8; x=7; scoreLeft=scoreLeft+1; } } //Set the ball to bounce if hits left paddle if (x<6) { if(y>leftPaddle-2 && y<(leftPaddle+12)) { xDir=-xDir; } //if miss else { y=rightPaddle+8; x=115; scoreRight=scoreRight+1; } } //set ball to bounce top or bottom if (y>93 || y<10) { yDir=-yDir; } //Left Paddle Control leftPaddle=analogRead(leftPot); leftPaddle=map(leftPaddle,0,1023,10,85); TV.draw_line(5,leftPaddle,5,(leftPaddle+10),1); //Right Paddle Control rightPaddle=analogRead(rightPot); rightPaddle=map(rightPaddle,0,1023,10,85); TV.draw_line(120,rightPaddle,120,(rightPaddle+10),1); //game over if (scoreLeft>9) { TV.clear_screen(); TV.print_str(25, 25, "Player 1 Wins!"); TV.print_str(28, 50, "(player 2 sucks)"); //make fun of player 2 delay(50000); scoreLeft=0; scoreRight=0; } if (scoreRight>9) { TV.clear_screen(); TV.print_str(10,25, "Nice try Player 1"); TV.print_str(2,50, "player 2 still sucks"); //make fun of player 2 delay(50000); scoreRight=0; scoreLeft=0; } //delay TV.delay_frame(1); }

Problems encountered:

At first there was a problem with the library we were using since it was for PAL (foreign) televisions rather than NTSC (U.S.) televisions. Once we had the right library, the only problems we had were with programming errors. Those were an easy fix.

What we'd like to add:

If we had more time, we'd add a start menu, a game start/restart button, sound, and a way to make the game harder if you go too long without scoring.