MonoPong game on Arduino

Do you remember the famous game from the ’70s called Pong?
pong

Personally I don’t because I’m too young for that but I like the game and it’s a nice challenge to recreate it in 1D.

SAM_0261

I came across the instructible below a few months ago and got excited about it.

http://www.instructables.com/id/monoPong/?ALLSTEPS

You’re asking why? I found it very cute to build a circuit like this only using cmos chips and a 555 timer. Of course I bought all the components in a local store and built it myself but after it was done I felt that something was missing. The problem was that there was no programming in there and hooking up all those wires also took me quite some time so I thought it’s time to implement the same thing using an Arduino and a lot less wire.

It’s a fun one afternoon project to do and you can even do it with your kids.

List of parts needed:

  • an Arduino (I have a Duemilanove)
  • LEDs: 8 of the same color and 2 different colored for the sides
  • resistors: I’m using 470Ohm ones but what you need depends on your LEDs
  • a potentiometer: I used a 100k one
  • jumper wires: mostly male but you’ll need 3 females for the potentiometer
  • a breadboard
  • 2 pushbuttons

SAM_0270

For conveniency I’m including all the “complicated” code here:

int delayTime = 100;
const int buttonAPin = 2;
const int buttonBPin = 3;
//int buttonAState = 0;
//int buttonBState = 0;
int playerAScore = 0;
int playerBScore = 0;

boolean playerAtoB = true;

void playerPass()
{
  if(playerAtoB)
  {
    if(digitalRead(buttonBPin) == HIGH)
    {
      playerAtoB = !playerAtoB;
      ++playerBScore;
    }
    else 
    {
      ++playerAScore;
    }
  }
  else
  {
    if(digitalRead(buttonAPin) == HIGH)
    {
      playerAtoB = !playerAtoB;
      ++playerAScore;
    }
    else 
    {
      ++playerBScore;
    }
  }
}

void printScores()
{
  Serial.println("*** Scoretable ***");
  Serial.print("Player A: ");
  Serial.println(playerAScore, DEC);
  Serial.print("Player B: ");
  Serial.println(playerBScore, DEC);
}

void setup() 
{             
  Serial.begin(9600);

  for(int i=4; i<12; ++i)
    pinMode(i, OUTPUT);     
  pinMode(buttonAPin, INPUT);     
  pinMode(buttonBPin, INPUT);     
}

void loop() 
{
  delayTime = analogRead(A0);
  if(playerAtoB)
  {
    for(int i=4; i<12; ++i)     
    {       
       delayTime = (analogRead(A0)/10)+10;
       digitalWrite(i, HIGH);
       delay(delayTime);
       digitalWrite(i, LOW);
       delay(delayTime);
    }
  }
  else
  {
    for(int i=11; i>3; --i)
    {
       delayTime = (analogRead(A0)/10)+10;
       digitalWrite(i, HIGH);
       delay(delayTime); 
       digitalWrite(i, LOW);
       delay(delayTime); 
    }
  }
  playerPass();
  printScores();
}

SAM_0267

References and similar projects

http://www.instructables.com/id/monoPong/?ALLSTEPS

https://sites.google.com/site/alastairparker/arduinopong

http://blog.makezine.com/2010/08/21/arduino-pong-1/

http://www.jaxhax.org/?p=191

http://www.instructables.com/id/Ardu-pong-the-Arduino-based-pong-console/?ALLSTEPS

http://www.instructables.com/id/2-player-Pong-using-Arduino/?ALLSTEPS

http://blog.bsoares.com.br/arduino/ping-pong-with-8×8-led-matrix-on-arduino

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s