252
Part II: Advanced Hacks, Tools, and Techniques
Software Setup Instructions
After you have verified that power is going to the chips, it is time to pro-
gram the microcontroller inside the IR cannon and the hit-sensor board. I
chose the PIC16F876A controller, which is versatile and reasonably priced.
You will need to locate a programmer for this part; I used the ICD2 pro-
grammer/emulator from Microchip. A large number of companies offer
low-cost (less than $50) programmers on the Web. Do a quick search for
“PIC programmer” and ensure that the model you choose can program the
PIC16F876A (or whatever controller you use).
I wrote the control software for this hack in C to allow easy debugging. I
used the C2C compiler from http://www.picant.com/ as my C compiler. The
very efficient C2C compiler targets the PIC family of processors.
After you purchase a programmer,
download an evaluation copy of the
C compiler. Compile the code, and
then program the processor.
Software operation
The software looks for incoming IR
signals and generates outbound IR
cannon signals. A simple flowchart
illustrating the logic is shown in
Figure 13-13.
The IR cannon can be fired only
15 times, and the vehicle can take
only four hits before it becomes dis-
abled. Note that the four LEDs are
used for three different purposes;
the total number of hits will display
on the LEDs in binary notation.
When a near miss occurs, the LEDs
will momentarily flash. After each
shot, the total remaining shots flash
in binary on the LEDs. When all
hits are exhausted, all of the LEDs
flash on and off. I’ve provided all
the source code for the project in
Exhibit B so you can make your own
modifications.
Figure 13-13: System software flowchart
Initialize system. Set
HIT_COUNT=0,
SHOT_COUNT=15
Has the IR sensor
been triggered?
YES
NO
Is the IR
sensor signal duration
at least 200 msec
long?
NO
YES
Pulse all LEDs ON
for 200 msec
Near miss
Has a
FIRE_LED signal from
the radio been
received?
YES
NO
SHOT_COUNT=
SHOT_COUNT-1
Light up in binary a
number of LEDs equal to
SHOT_COUNT for 1 sec
Is SHOT_COUNT=0?
NO
YES
Generate a 38kHz signal
modulated at 2(or 3) kHz
for 500 msec
HIT_COUNT=HIT_COUNT
+1
Is HIT_COUNT > 4?
NO
Light up a number of LEDs
equal to HIT_COUNT
YES
Flash all LEDs
on and off at a
rate of 1Hz
Destroyed
Fire IR cannon
Software Setup Instructions
ch13_rc.indd 252
1/22/2002 4:44:29 PM
253
Chapter 13, How to Make RC Cars Play Laser Tag
Compile the code
Download a copy of the C compiler and install it on your PC. You will be
able to run the demo version for a few weeks before you need to enter a
validation key, which you can purchase if you like the product.
Start by creating a New Project, named whatever you like. You can see the
New Project menu item in the upper left of Figure 13-14.
Next, create a new file and either type in or download (from http://www.
oreilly.com) the C code into the compiler editor. The New File menu item is
shown in the upper right.
Save the file using a name with the extension “.c”. Add the file to the proj-
ect, as shown in the lower left.
Figure 13-14: Software compiler operation
Software Setup Instructions
ch13_rc.indd 253
1/22/2002 4:44:29 PM

Get Hardware Hacking Projects for Geeks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.