This time, I'm back with a project in which two RC remote controls are used to move the paddles in Pong. Watch me lose it against my brother here ;)
But now how does it work?
Let's start by looking at the RC controls: For each channel a pulse with a width of 0.7 up to 2 milliseconds is issued from the remote control. A pulse shorter than 1.5 ms would turn a servo left, one greater 1.5 would turn it right. You can read about this in some more detail here.
The analogue RC receivers' signal output lines are connected directly to digital inputs (ports 3 and 5) of my Arduino. They run fine with the 5V power from the Arduino, even if it draws its power from an USB port.
On the Arduino, a very simple sketch measures the control pulse lengths via "pulseIn". During the first five seconds, the gathered values are investigated for their minimum and maximum, so you will have to turn the knobs on your RC controls to their farthest extend here. The range of the pulse lengths is then mapped to a single byte for each channel.
The actual Pong game runs on a PC within the Processing IDE. To achieve this, I adapted the "SerialCallResponse" example sketch and added a Pong implementation in Java. There is a class called "ControlValues" which serves as an interface between the game and the Processing sketch. This approach is in no way thread-safe, but since game is timer-based and the Processing sketch is event-based, it seemed the easiest way to connect both using static variables.
The Processing sketch first starts the game and then begins querying the Arduino for new control values. To simply retrieve the values, it sends an 'A', to which the Arduino responds by sending the current values.
By sending a 'B' or 'C', the sketch can make the Arduino play some beeps in addition to sending the values. This should give you the real retro feeling! To hear the beeps, simply connect a speaker to port 7 (via transistor or op-amp). You may notice that sometimes a beep isn't played (ball touches the paddle, but there's no sound). This is due to the threading problems mentioned above.
To play you can download the Arduino sketch and Processing sketch.