122-28029 Parallax Inc, 122-28029 Datasheet - Page 90

GUIDE STUDENT SMART SENSORS

122-28029

Manufacturer Part Number
122-28029
Description
GUIDE STUDENT SMART SENSORS
Manufacturer
Parallax Inc
Datasheet

Specifications of 122-28029

Accessory Type
Manual
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
Smart Sensors
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
Page 78 · Smart Sensors and Applications
Clamping the Input Range
The best way to make sure the output values do not exceed the output range is to make
sure the input values do not go outside the input range. For example, if you do not want
the output of this command to go outside −127 to 127, the most convenient approach is to
make sure that the input values do not go below 1875 or above 3125. Here is a modified
version of
Before subtracting 1875 from the
MIN 1875
value
However, if it's storing something less than 1875,
Likewise, if it's storing something above 3125,
Example Program: TestScaleOffset.bs2
Figure 3-11 shows what the Debug Terminal looks like as the next example program is
tested. When you enter input values (separated by commas) into the Debug Terminal's
Transmit windowpane, the program displays the scaled and offset equivalent in the
Debug Terminal's Receive windowpane.
' Smart Sensors and Applications - TestScaleOffset.bs2
' Test scaling from an input range of 1875 to 3125 to an output
' range of -127 to + 127.
'{$STAMP BS2}
'{$PBASIC 2.5}
value
DEBUG CLS, "Enter values (1875 to 3125)...", CR
DO
DEBUG ">"
variable is storing a number in this range, the
value = (value MIN 1875 MAX 3125) - 1875 ** 13369 - 127
Enter, save, and run TestScaleOffset.bs2.
value = value - 1875 ** 13369 - 127
Always round your ScaleConstant result down, even if the result is already an
integer! Otherwise, the largest value in your input scale might be one value outside the
output scale's range.
and
MAX 3125
VAR
Word
, to make sure
value
value
variable, this command uses two operators,
MAX 3125
stores something in this range. If the
MIN 1875
MIN
that prevents the problem.
and
changes it to 3125.
MAX
will change value to 1875.
operators leave it alone.

Related parts for 122-28029