Figure 4. Title screen.
Figure 5. Paddle color selection
at that point and constantly execute the RCTIME
command, you will notice
that — most of the time —
a value of 134 will be
returned, but values of
133 and 135 will also be
returned on occasion.
You can reduce this
with hardware changes,
such as better tolerance components and high precision
potentiometers. You can also reduce it with software,
such as reading the paddle 10 times and then taking the
average value. You can experiment with this in Stamp
Pong. Resistor R2 completes the paddle circuit. This is
simply protection against short circuits. When the capacitor is completely charged up, the negative side is at 0
volts. Executing the HIGH 1 command would cause an
instantaneous in-rush current to occur during the discharge. This resistor is just some insurance to keep the
BASIC Stamp 2 from experiencing high in-rush currents.
Figure 6. Main game screen.
RCTIME. The potentiometer is connected to the negative
side of capacitor C1. The command RCTIME is used by the
BASIC Stamp 2 to record the time it takes for a pin to go
from one logic state to another. Refer to the following code:
The first two commands, HIGH 1 and PAUSE 1, turn
pin P1 into an output logic-high pin for 1 mS. This
discharges the capacitor before executing RCTIME. When
RCTIME is executed, pin P1 is turned into an input
and capacitor C1 will start to charge up through the
potentiometer in the paddle. When pin P1 turns from a
logic high state to a logic low state, the value is stored in
the variable “PADDLE.” The combination of the 0.47 µF
capacitor and 1K ohm potentiometer was chosen so the
command would execute quickly; the less time the
command waited for the capacitor to charge, the faster the
game play could be. They were also chosen so the
RCTIME command will return as close to a single byte
number (0-255) as possible on the BASIC Stamp 2.
Paddle jitter may occur in your programs. Jitter is
caused when the paddle is not being moved, but the
RCTIME command returns a different value for each read.
For example, you move the paddle to a location where the
variable “PADDLE” is equal to 134. If you hold the paddle
NUTS & VOLTS
With the exception of the ezVID and the BASIC Stamp 2, these
components can be found at any local electronics store or online distributor. The board in this article was assembled on a RadioShack proto-board
in under half an hour. For the + 5 V supply, a 78L05 voltage regulator in a
TO-220 case sourced from a 9 VDC wall wart power supply was used.
1 ezVID Serial Video Module (can be purchased from Multilabs
1 BASIC Stamp 2 (can be purchased from Parallax, Inc., at www.
1 10K ohm, 1/8 W, 5% resistor
1 150 ohm, 1/8 W, 5% resistor
1 1K ohm, single turn, linear potentiometer
1 0.47 µF, 16 V electrolytic capacitor
1 SPST momentary normal-open push-button
1 Four-pin female header
1 24-pin 0.6” DIP socket
1 + 5 VDC power supply
The interface and communications stuff is out of the
way, so let’s get on to the real stuff. When the game first
executes the variables and the initial pin settings are done,
the program will wait to make sure enough time has passed
for the ezVID to initialize itself, send the command to clear
the screen, and then begin loading custom characters. The
custom characters are an off light bulb, an on light bulb, a
paddle, a selection arrow, a brick piece, and the ball.
The main game code is then executed. The game is
broken up into three pieces: the title screen, the paddle
color selection screen, and the main game screen. These
are shown in Figures 4 through 6, respectively. The title
screen is shown first and is also the screen that the game
returns to when the game is over. It is simply the name of
the game “STAMP PONG” surrounded by a constantly
rotating light show. Instructions appear to prompt the
game player to press the fire button when ready. This code
is a tight loop where the BASIC Stamp 2 is constantly
sending commands to the ezVID to place a “light on”
character, place a “light off” character in the same
position, increment the position, and check to see if the
fire/select button on the paddle has been pressed. As long
as the fire/select button has not been pressed, the rotating
light show will continue to go around the game title.
When the fire/select button is pressed, the title screen
is cleared and the paddle color selection screen is drawn.
Here, the user can select the color of the paddle in the
game. This is the first instance where the code to read the
paddle is used.
The value of “PADDLE” is used to determine the
position of the arrow. Two conditions are checked; if the
value of PADDLE is greater than or less than the selection