Parallax Boe-Bot Student Manual page 228

Hide thumbs Also See for Boe-Bot:
Table of Contents

Advertisement

Page 214 · Robotics with the Boe-Bot
Constants can even be used to calculate other constants. Here is an example of two
constants, named
LeftThreshold
four constants just discussed. The
used in the program to figure out whether or not the flashlight beam has been detected.
'
LeftThreshold
CON
RightThreshold CON
The math performed on these constants is an average, and then a scale. The average
calculation for
LeftThreshold
multiplied by 5 and divided by 8. This means that
5
value is the
/
of the average of
8
Math expressions in PBASIC are executed from left to right. First,
added to
LeftAmbient
divided by 8.
Let's try this:
LeftBright
128 / 2 = 64.
64 * 5 = 320
320 / 8 = 40
You can use parentheses to force a calculation that is further to the right in a line of
PBASIC code to be completed first. For example, you can rewrite this line of PBASIC
code:
pulseRight = 2 - distanceRight * 35 + 750
like this:
pulseRight = 35 * (2 – distanceRight) + 750
In this expression, 35 is multiplied by the result of (
product is added to 750.
Example Program: FlashlightControlledBoeBot.bs2
Enter FlashlightControlledBoeBot.bs2 into the BASIC Stamp Editor.
Substitute your
1) in place of the value 108 in the
and
RightThreshold
LeftThreshold
Average
LeftBright + LeftAmbient / 2
RightBright + RightAmbient / 2 * 5 / 8
is
LeftBright
and
LeftBright
. This value is divided by 2. The result is then multiplied by 5 and
+
LeftAmbient
measurement with no flashlight beam (from Table 6-
timeLeft
LeftAmbient CON
that are calculated using the
and
RightThreshold
Scale factor
* 5 / 8
+
/ 2. That result is
LeftAmbient
is a constant whose
LeftThreshold
.
LeftAmbient
LeftBright
= 20 + 108 = 128.
2 – distanceRigh
directive.
constants are
is
t), then the

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Boe-Bot and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF