cost you around $5 for the parts,
depending on what you have in your
junk box. As far as assembly goes,
I soldered the 78L05, diode, and
resistor directly to the connector.
then print the received value, as well
as the Rot value.
Note that you have to access the
ComInput command to pull the
data out of the buffer or the ComBuff
command will just keep getting larger
and won’t ever return a 0.
First, Second, Third, and
A call to initBike is also made.
Notice that I am using com port 4. You
will need to pass the com port number
your interface is connected to.
Now, for the fun part. We will use a
development program called Zeus.
There is even a special free Nuts &
Volts version up on the Nuts & Volts
website ( www.nutsvolts.com). Let’s see
how this will work.
I’m going to start with a simple
program just to test if the sensor is
Program 1 is fairly straightforward. We open up the com port. If the
ComOpen returns a 0, we have an
error so we display an error message
and exit the program.
Once we have an open port,
we raise DTR with the ComDTR
command. This provides power to
We then run a very tight loop that
checks the status of the com buffer
with the ComBuff command. If it
returns anything greater than 0, we
know we have a sensor event.
We increment the Rot variable
Race Program 1
I’m not going to list the Race
Program 1 here because it can be
found on the Nuts & Volts website, as
well as the Kronos Robotics website. I
will, however, walk you through each
section of the code.
There are four functions used to
make up Race Program 1.
Here we set a variable called
ticks. This variable will increment
every 10 milliseconds. Once we get a
tick value greater than 3, we reset the
counter and using a random number
generator, increment the position of
each of the bot pips. For instance,
take the following snipit of code:
This function opens the indicated
port and sets DTR to power the
if Random(1, 10) > 4 then
rots(2) = rots(2) + 1
• Draw Track()
This function draws the track. You
can change the FormBrush values to
change the track colors.
This function plots a player pip at
a particular position on the track
based on its Rotation value. Note that
player 1 is the sensor and players 2-4
are the bot players.
Program 1. Sensor Test
‘Exercise Bike Sensor Test
gconst chBike 1
dim Rot as integer
if ComOpen(chBike,baud=9600,port = 4) = 0 then
MsgBox(“Error Opening Com Port”)
‘Power up the connector
if ComBuff(chBike) > 0 then
Rot = Rot + 1
This is the entry
point of the program.
This is where most of the
work gets done and, due
to its complexity, it is
broken down into its own
Here, a random number between
1 and 10 is generated. If it is greater
than 4, we will increment the bots
rotation count. This equates to a 40%
chance of this particular pip advancing one position every 40 ms.
By changing the value from 4 to 8,
you effectively double the skill level
of this bot. This would give the
appearance of that bot running faster
After the rotations are calculated,
we then draw the track and plot all
four player pips.
Main Calculate Position
Here, we do a quick bubble sort
to calculate each players position in
Here we set up the
program by creating a
Main Display Lap Data
Here, we display the text data
indicating the player name, his position, and number of laps completed.
Tots Total of all
Rots Current rotations
of current lap.
Pos Race position.
Main Check Com Buffer
Here, we check for activity on the
com buffer. If we have activity, we increment the (player 1) rotation counter.
I consider this a starting point as