28129 Parallax Inc, 28129 Datasheet - Page 67

TEXT BASIC ANALOG & DIGITAL

28129

Manufacturer Part Number
28129
Description
TEXT BASIC ANALOG & DIGITAL
Manufacturer
Parallax Inc
Type
Programmingr
Datasheet

Specifications of 28129

Style
Book
Title
Basic Analog and Digital
Contents
Basic Analog and Digital Text
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
In long division, calculating the part of the answer to the right of the decimal point is
repetitive. We multiply the remainder by 10, then divide by 255 again, then take another
remainder, multiply it by 10, and divide by 255 again, etc. A shortcut to this procedure is
to take the remainder, and multiply it by 100, then divide by 255. This gives us two
decimal places. Let's try it.
Remember: the BASIC Stamp cuts off everything to the right of the decimal point
without rounding. This is called truncating. The result we get is 23. This result should
have been rounded up to 24 because 23.5294 is more than half way to the next integer
value, 24. For now, let's stick with 23 to the right of the decimal point.
Our answer using this algorithm is the integer 3 to the left of the decimal point, and the
integer value 23 to the right of the decimal point. Since we used only integers in our
arithmetic, it should work using PBASIC and the BASIC Stamp.
Since the BASIC Stamp works with integers, it's not surprising that there is a PBASIC
command to calculate the integer remainder of a division problem. The operator for
division is / and the operator for getting the remainder is //. Let's try converting this
algorithm into PBASIC code to do the work for us. The steps for long division below
show the PBASIC commands corresponding to the steps in the algorithm.
v=5*adcBits/255
v2=(100*R)/255
Voltage
(60
What’s an Algorithm? An algorithm is a procedure for solving a problem. The procedure is
broken down into repeatable steps.
×
100)
=
÷
5
255
×
(Decimal
=
6000
255 5 adcBits
255 100 r
255
÷
A/D
×
255
×
v2
Output)
=
23.5924...
v r
+
=
3
+
a
Integer
remainder
Math
R=(5*adcBits//255)
23
of
60

Related parts for 28129