27220 Parallax Inc, 27220 Datasheet - Page 59
27220
Manufacturer Part Number
27220
Description
BOOK STAMPWORKS
Manufacturer
Parallax Inc
Datasheet
1.27220.pdf
(230 pages)
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
- Current page: 59 of 230
- Download datasheet (3Mb)
Time to Experiment · Page 49
Behind the Scenes
One of the key aspects of this program is that it demonstrates how to put more
randomness into the pseudo-random nature of the RANDOM function. This is done by
adding a “human touch.”
The program waits in a loop at Main. The top of this loop calls Get_Random to
create a pseudo-random value, a tone for the speaker and to put the new pattern on
the LEDs. On returning to the loop, the tone is played and the button input is
checked for a press. The program will remain in this loop until we press the button.
The BUTTON instruction is used to debounce the input. Here’s what gives the
program its randomness: the time variations between button presses (during which
the RANDOM function is continually called, hence tumbling the value). When the
button is pressed, the LEDs are lit and cleared to simulate the game resetting. Then,
a FOR-NEXT loop is used to simulate the rolling action of a slot machine. For each
roll, a “click” sound is generated and the delay between clicks is modified (increased
by 10%) to simulate natural decay (slowing) of the “wheels.”
If all six LEDs are lit after the last spin, the program plays a little light and sound
show to celebrate our good fortune. This section uses LOOKUP to play a preset
pattern of LEDs and tones before returning to the top of the program. If any of the
LEDs are not lit, a groan will be heard from the speaker and the game will restart.
Taking It Further
Can you modify the program so that fewer than six LEDs are required for a win?
How can this be done?
Write Code like a Pro
Instead of waiting for an actual “win” we can rig the game to win every time by
inserting a line of code:
pattern = %00111111
. . . before the section that tests the pattern bits. This is useful for fine-tuning the
celebration routine – just be sure to remove this code before delivering the final
Related parts for 27220
Image
Part Number
Description
Manufacturer
Datasheet
Request
R
Part Number:
Description:
Microcontroller Modules & Accessories DISCONTINUED BY PARALLAX
Manufacturer:
Parallax Inc
Part Number:
Description:
BOOK UNDERSTANDING SIGNALS
Manufacturer:
Parallax Inc
Datasheet:
Part Number:
Description:
COMPETITION RING FOR SUMOBOT
Manufacturer:
Parallax Inc
Datasheet:
Part Number:
Description:
TEXT INFRARED REMOTE FOR BOE-BOT
Manufacturer:
Parallax Inc
Datasheet:
Part Number:
Description:
BOARD EXPERIMENT+LCD NX-1000
Manufacturer:
Parallax Inc
Datasheet:
Part Number:
Description:
CONTROLLER 16SERVO MOTOR CONTROL
Manufacturer:
Parallax Inc
Datasheet:
Part Number:
Description:
BASIC STAMP LOGIC ANALYZER
Manufacturer:
Parallax Inc
Datasheet:
Part Number:
Description:
IC MCU 2K FLASH 50MHZ SO-18
Manufacturer:
Parallax Inc
Datasheet: