Problem Description
Here's a program illustrating the use of timers to
control the lights of a simulated
drag strip starting tree.
Background & Techniques

Drag racing is a sport in which two vehicles race from a standing start
for a fixed distance, usually 1/4 mile, down a straight track with two
lanes.
This program was prompted by a user who is developing a drag strip
simulation and wanted help in triggering the start
with some visual clue. My original version simply changed the color of
a circular shape at some random interval after an "Activate" button was
clicked. That evolved into a fairly complete model of the standard
starting "tree", the Christmas tree, used in real races.
Lights are arranged in two columns, one for each racer.
From top to bottom the rows indicate
 |
pre-staged (7 inches from the starting
line), |
 |
staged (at the starting line),
|
 |
three rows of yellow countdown light,
|
 |
the green "Go" light,
|
 |
and a red light if the racer starts
too soon.
|
Two users may use buttons to pre-stage and stage their
dragsters and click the "Activate start sequence" button to start the
countdown. When the green light is lit, "P' or "Q" keys will report reaction
times for each player. Pressing the keys too soon results in a red
light condition on the tree.
An "Auto stage" checkbox automates pre-staging, staging, and
activating start sequence lights.
For programmers, I have tried to comment the code well enough to make
clear how the timers work. Timer1 controls the yellow lights
and the green start light on the tree. The StartLightsOn
integer starts at 0 and is incremented each rime the timer even exit occurs.
Lights are turned within the exit by changing the color of the appropriate
Tshapes from a dark to light shade of yellow or green.
There are two starting modes used in drag racing. "Sportsman"
mode triggers the three yellow lights and the green start light at 1/.2
second intervals. "Professional" mode lights all 6 yellow
lights simultaneously followed by the green lights 0.4 seconds later.
The current time of day is saved as StartTime when the green lights
are lit.
The "Auto Activate" checkbox introduces two additional timers,
AutoTimer1 and AutoTimer2, one for each racer which are triggered
at random intervals to simulate their pre-stage and stage lights. When
both racers are staged, the Onclick event exit for the Activate
button is called to start the countdown process.
The Boolean form property "KeyPreview" has been set to true to
allow form KeyPress event exits to be taken regardless of which
control has the focus. Keys other than P or Q
are ignored; those two keys cause the current time minus the StartTime value
to be displayed as the response time for the appropriate racer.
No actual racing here - we'll leave that for the future.
Running/Exploring the Program
Suggestions for Further Explorations
I believe that in real drag racing there is a minimum acceptable
reaction time, below which the driver is red-lighted because he must have made a
'lucky guess". If true, that restriction could be implemented here also.
|
Original Date: July 21, 2009 |
Modified:
August 05, 2009 |
|