27220 Parallax Inc, 27220 Datasheet - Page 65

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
return a remainder of zero, using modulus in this manner causes mode to “wrap-
around” from four to zero.
The final element of the main loop is called Show. This code uses ON-GOSUB to call
the code that will output the light sequence specified by mode. Modes A through D
work similarly, retrieving light sequences from the BASIC Stamp’s EEPROM (stored in
DATA statements). Mode E outputs a random light pattern.
Take a look at the code section labeled ModeA. The first thing that happens is that
the variable, offset, is updated – again using the “wrap-around” technique with
the modulus operator. The value of offset is added to the starting position of the
specified light sequence and the current light pattern is retrieved from EEPROM with
READ. Notice that the DATA statements for each sequence are labeled (SeqA, SeqB,
etc.). Internally, each of these labels is converted to a constant value that is equal
to the starting address of the sequence. The length of each sequence is calculated
with these constants.
(shortened or lengthened) without having to modify the operational code called by
Show. ModeE is very straightforward, using the RANDOM function to output new
pattern of lights with each pass through the main loop.
Take it Further
Add a new lighting sequence. What sections of the program need to be modified to
make this work?
Write Code like a Pro
The modulus operator (//) is extremely useful, yet shunned by many beginning
programmers as “mysterious.” It’s not, really, in fact its operation is very simple: it
returns the remainder of an integer division. In practice what this means is that the
modulus of any value will fall into the range of zero to the value minus one.
Beginners will often do this:
idx = idx + 1
IF (idx = 5) THEN
ENDIF
idx = 0
By using this technique, light patterns can be updated

Related parts for 27220