ArduinoLab8
Pong!
(This lab from Chapter 2 of Tom Igoe's great book Making Things Talk)
In this lab we are going to make a Pong game. The game itself will be displayed on your laptop using Processing. The Arduino will read in sensor values and send them to your Processing code.
Hardware.
In this project you will need to construct a circuit with the following:
- one reset button connected to digital 2. When the button is not pressed the circuit should be connected to ground with a pulldown resistor.
- one serve button connected to digital 3. When the button is not pressed the circuit should be connected to ground with a pulldown resistor.
- one analog sensor (potentiometer, light sensor, whatever) connected to analog 0 - controlling a paddle
- one analog sensor (potentiometer, light sensor, whatever) connected to analog 1 - controlling a paddle
Arduino/Wiring code
The code for the Arduino is Arduino Pong Code
To test whether everything is working so far, open the serial monitor. You should see something like:
284,284,1,1, 285,283,1,1, 286,284,1,1 289,283,1,1,
Processing code
The pong code for Processing is Processing Pong Code
You will need to experiment and come up with your own values for
float leftMinimum = 250; // minimum value of the left flex sensor float rightMinimum = 260; // minimum value of the right flex sensor float leftMaximum = 450; // maximum value of the left flex sensor float rightMaximum = 460; // maximum value of the right flex sensor
