Robotics with the Boe-Bot text v2.2

Appendix F: Balancing Photoresistors · Page 325
Now, we know how to correct the timeLeft variable so that it reports values similar to
the timeRight variable in this narrow range of light levels:
7timeLeft37.1timeLeft
7x37.1y
bmxy
)adjusted(
+×=
+=
+=
A Linear Equation in PBASIC
In most programming languages for PCs, this equation could be entered as-is. The
BASIC Stamp is a very tiny processor compared to a PC. Because of this, it takes an
extra step to multiply by a fractional value. You have to use the */ operator (it’s called
the “star-slash” operator). For the
timeLeft equation, the PBASIC code to adjust the
timeLeft variable can be done like this:
timeLeft = (timeLeft */ 351) + 7
The adjusted value of timeLeft after this line of code is executed is 1.37 times the old
timeLeft, plus 7.
Why did 1.37 become 351? The way the */ operator works is that you have multiply your
fractional value by 256, and place it to the right of the */ operator. Since 1.37 X 256 =
350.72 351, the value 351 goes to the right of the */ operator.
You can find out more about the */ operator in the BASIC Stamp Editor by clicking Help and
selecting Index. Type in */ in the field labeled “Type in keyword to find”. You can also look
up */ in the Binary operators section of the BASIC Stamp Manual.
Your Turn – Balance Your Photoresistors with m and b
In Table F-1, label the first timeLeft entry X1 and the second timeLeft entry
X2.
Label the first timeRight entry Y1 and the second timeRight entry Y2.
Use these equations and your X1, X2, Y1, and Y2 values to solve for m and b.
)xx(
)yy(
m
12
12
=
and
22
mxyb =