Figure 5. POT Scaling dialog in the Windows editor.
of the POT function is 255.
After connecting our POT
circuit, we'll select Pot Scaling from
the editor's Run menu (Note: This
feature became available in Version
2.1, Beta 1). Figure 5 shows the dialog for POT Scaling. We must first
select the POT pin from a dropdown. Then when we click Start, a
short program will be downloaded
to the Stamp (yes, this overwrites
the current program). Normally, we would turn the pot
until we get the lowest reading in scaling factor. Since we're
using a photocell, we adjust its value by shading it from
light. I decided to use a translucent foam cup over my components to determine the scale level (max resistance).
I applied the same scale factor to both circuits and
found that I got significantly different values given the
same light level (both covered with the foam cup). To
adjust for component differences, I tweaked the scaling
factor of the second "eye" circuit until both sensors
returned the same value under the same lighting.
Okay, let's look at the code:
Under most conditions, we'll
have at least one photocell reading, so we do a comparison to see
which side is getting the most light
(it will have the lowest value). Let's
assume that the left photocell had a
lower reading and go through that
section of code. The code for the
right side works identically.
We'll assume that the threshold is going to be exceeded and
preset the move variable to left (% 10). Next, we check the
value of the left photocell. If it's zero (swamped), there is
no need to check the threshold and we can exit. If it is not
swamped, we will subtract the right photocell reading from
the left and compare the result against the threshold. If the
threshold is exceeded, we exit, otherwise the move variable
is set to forward (%00). Since this is a demo program, we
should have some code to show us what's happening with
the sensors. Here's a short bit of code to do that:
POT EyeL, 145, lfEye
POT EyeR, 175, rtEye
DEBUG CLS, lfEye, CR, rtEye, CR
IF lfEye = 0 AND rtEye = 0 THEN Is_Dark
IF rtEye < lfEye THEN Is_Right
move = %10
IF lfEye = 0 THEN Eyes_Done
lfEye = rtEye - lfEye
IF lfEye >= Threshold THEN Eyes_Done
move = %00
move = %01
IF rtEye = 0 THEN Eyes_Done
rtEye = lfEye - rtEye
IF rtEye >= Threshold THEN Eyes_Done
move = %00
move = %11
BRANCH move, (Go_Straight, Go_Right, Go_Left,
The code starts by reading each "eye" into its own variable and displaying the readings in the DEBUG window.
Then we check to see if both values are zero; this will happen
in total darkness (due to the POT function timeout) or when
both photocells are swamped with light. In either, case we
want the robot to hold still. Setting the move variable to % 11
tells our main code that this is the case.
There's no magic here, we're simply using BRANCH
to jump to code that will display the direction of robot travel. This lets us test our "robot eyes" on a breadboard. Bend
the photocell leads so that they're oriented on the horizontal plane, and then turn them out from each other to
expand the field of view. By shining a flashlight spot in
front of the photocells, the DEBUG window will show the
robot's movement behavior.
All that's left to do is replace the DEBUG statements
with appropriate motor controls (and you know how to do
that) to create a robotic photovore — kind of like an electronic kitten (cats love to chase flashlight spots), only this
one won't scratch furniture or need a litter box!
Well, I told you we'd take it easy this time, and hopefully you agree with me that this was no less fun that we usually have. Modifying an existing motorized toy is a great way
to get kids into robotics — no matter what their age.
Until next time, Happy Stamping. NV