by littleBits May 9, 2014
Play Pong on your computer screen using two analog sensor modules as inputs. This sketch will allow you to send two analog sensor values from the Arduino module to a Processing sketch that is running a version of the game Pong. The Pong paddle positions move based on the sensor values in this two player game. For more “getting started” sketches, click here. To learn more about coding, find examples on Arduino’s website.
Play Pong on your computer screen using two analog sensor modules as inputs.
This sketch will allow you to send two analog sensor values from the Arduino module to a Processing sketch that is running a version of the game Pong. The Pong paddle positions move based on the sensor values in this two player game.
For more “getting started” sketches, click here.
To learn more about coding, find examples on Arduino’s website.
Videos and Recipes
Download the Arduino software to your computer (it's free!) and open the "Analog Pong" sketch. You will also need to download Processing to run the Processing sketch.
The "Analog Pong" Arduino and Processing files can be found on this page in the "other files" section. When you unzip the analog_pong_processing folder, you will want to open and run the file named analog_pong_processing.pde
NOTE: Don't take this file out of the folder. It needs to be in the same location as the four other files in the folder.
Build your circuit (see the photo gallery for an image of the setup). Make sure your two dimmers are connected to the analog input pins, A1 and A0.
Plug the micro USB cable into both the Arduino module and a USB port on your computer.
Turn your power module on. You should see a red light illuminate on the power module and a yellow light flash on your Arduino module.
In the Arduino program, select your board. Go to Tools>Board>Arduino Leonardo. This littleBits Arduino module is modeled after the Arduino Leonardo and is therefore compatible.
Next select the serial port that the Arduino will communicate over by going back to "Tools" and selecting the correct port in the "Port" section. The name of the port will depend if you are on a Mac or Windows computer. On a Mac, it will start with /dev/tty.usbmodem... and a PC will start with COMM… In Windows, you can look for the USB serial device in the ports section of the Windows Device Manager. If you are on a Linux machine, the port will look like /dev/ttyUSB…
To upload the Arduino sketch to your Arduino module, press the arrow button in the top left corner of the screen. You will see a blue bar at the bottom of the window that says "compiling sketch", and you should see two yellow lights flash on your Arduino module when this happens. The upload is complete when you see "done uploading" at the bottom of your sketch window.
Now, switch over to the processing sketch. Press the "play" button in the Processing window (top left corner). This will open another window that says "littleBits PONG". Press any key on your keyboard to start the game and move the dimmers to adjust the Pong paddles.
If you are unable to move your Pong paddles, you may need to make a slight adjustment to the code in the processing sketch so that you connect to the correct serial port.
Scroll down until you find this line of code:
myPort = new Serial(this, Serial.list(), 9600);
You will need to replace the 0 in Serial.list(). Start counting up from 0. After each change you make, try and run the game. We found that we needed to replace the 0 with the number 2.