Aluminum foil is a low-cost and effective material you can use to create a capacitive touch sensor. This project shows you how to build and program a capacitive touch sensor circuit with an OLED color display to play the Blockly version of the game Pong. This program will work by calibrating a range of R/C time decay values the foil produces, then uploading the calibration into the main project. Let's jump in!
The Pong game consists of two separate programs. The first being a calibration program to scale and constrict the R/C time values that the foils produce, and the second being the main game code. Note that the size of the aluminum foil squares can vary and work well up to around 12” x 12” as long as both are equal in size.
Included in the FLiP Try-it Kit (#32023) [1]:
Not included in the FLiP Try-it Kit:
Build the circuits shown below, following the wiring diagram and schematics. Each alligator clip attaches to one foil sensor.
Double check to make sure the OLED display is wired correctly, and the aluminum foil sensors are not overlapping but are directly adjacent to each other.
First, we need to calibrate your foil sensors.
The Terminal will display values from the RC time block based on which square of foil your hand is hovering above.
These values may have an extremely large range at first. In the game, you will use the map block, which will do the math and automatically scale and translate these values for you.
Let's try it out and see what happens!
The example shows values of -260 on the far right and 610 on the far left (yours will probably be different - everything from the size and thickness of the foil squares to the size of your hands, to the humidity in the air, will have an effect). You may need to experiment with these values to finetune the game's performance.
For more information about how the map block works, click here [8] to view it in the reference files.
Record the most extreme values for either side. Now that you have these values, you are ready for the next step.
Give the game a try and see how it works. If it doesn't work quite right, recheck the circuit diagrams and schematics on the first page of this project to be sure your connections are correct.
Capacitive touch sensing allows detection of human interaction with the circuit without requiring physical touch. The circuit provides some level of detection up to almost a foot away. This detection is accomplished using a modified resistor/capacitor circuit with a single 10 MOhm resistor between two Propeller I/O pins.
The aluminum foil and your body make up the two plates of the capacitor. (Your body also provides some additional resistance and a pseudo ground connection.) The amount of time it takes for the circuit to discharge from a high to a low logic level varies with your proximity to the aluminum foil. But this circuit and code have a twist - we’re using PWM to set a logic level halfway between the Propeller’s high and low values.
The Pong game is one of the earliest arcade-style video games, originally released in 1972 by Atari. It’s a simple, two-dimensional game in which a player uses a paddle to knock a ball off adjacent walls. Pong has a long history with many adaptations for a variety of hardware consoles and platforms. It is among the simplest games to code.
Wikipedia hosts a complete summary of Pong [10] if you're interested in the full history.
Change the difficulty of the game and add sound effects with a piezo speaker. Test the following:
Try modifying your program to change the colors of the game. Do the colors of the paddle, ball, and walls have an effect on gameplay? Is it easier to see the ball, and therefore more likely to hit it, if it is colored differently from the paddle? What if all game components are the same hue?
Links
[1] https://www.parallax.com/product/32023
[2] https://www.parallax.com/product/805-00016
[3] https://www.parallax.com/product/700-32023
[4] https://www.parallax.com/product/32123
[5] https://www.parallax.com/product/800-00042
[6] https://www.parallax.com/product/28087
[7] http://blockly.parallax.com/blockly/editor/blocklyc.jsp?project=10635
[8] https://learn.parallax.com/support/reference/propeller-blocklyprop-block-reference/operators/numbers
[9] http://blockly.parallax.com/blockly/editor/blocklyc.jsp?project=10636
[10] https://en.wikipedia.org/wiki/Pong