27220 Parallax Inc, 27220 Datasheet - Page 226

BOOK STAMPWORKS

27220

Manufacturer Part Number
27220
Description
BOOK STAMPWORKS
Manufacturer
Parallax Inc
Datasheet

Specifications of 27220

Accessory Type
Booklet
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
StampWorks
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Not applicable / Not applicable
What happened to the -1? It was applied to the divisor and that value is added to
the intermediate result.
The key to mastering modulus is remembering that it will return a value between
zero and the divisor used. Let’s say you want to generate a pseudo-random number
between 20 and 50 when a button is pressed. Here’s how:
Do you see how this works? The span between 20 and 50 is 30, so we use 31 as the
divisor for modulus.
Use Conditional Compilation
BASIC Stamp microcontrollers have been around a few years, and as would be
expected, new models are faster and have more features than the older ones. The
BASIC Stamp IDE allows for conditional compilation so that you can construct a code
that will run on any BS2 module. The most common problem for BASIC Stamp
programmers when moving from one module to another is with SERIN and SEROUT.
By using conditional compilation to define baudmode constants these problems are
eliminated. The code fragment below is abbreviated from the definitions provided in
my standard programming template (Template.BS2).
Main:
#SELECT $STAMP
#ENDSELECT
DO
LOOP UNTIL (StartBtn = Pressed)
selection = randVal // 31 + 20
#CASE BS2, BS2E, BS2PE
#CASE BS2SX, BS2P
#CASE BS2PX
RANDOM randVal
T2400
T9600
T19K2
T38K4
T2400
T9600
T19K2
T38K4
T2400
T9600
T19K2
T38K4
CON
CON
CON
CON
CON
CON
CON
CON
CON
CON
CON
CON
396
84
32
6
1021
240
110
45
1646
396
188
84

Related parts for 27220