Chapter 3: Assemble and Test Your Boe-Bot
· Page 109
Programming the Start/Reset Indicator
The next example program tests the piezospeaker. It uses the
FREQOUT
command to send
precisely timed high/low signals to a speaker. Here is the
FREQOUT
command’s syntax:
FREQOUT
Pin, Duration, Freq1 {,Freq2}
Here’s an example of a
FREQOUT
command that’s used in the next example program.
FREQOUT 4, 2000, 3000
The
Pin
argument is 4, meaning that the high/low signals will be sent to I/O pin P4. The
Duration
argument, which is how long the high/low signals will last, is 2000, which is
2000 ms or 2 seconds. The
Freq1
argument is the frequency of the high/low signals. In
this example, the high/low signals will make a 3000 hertz, or 3 kHz, tone.
Frequency can be measured in hertz (Hz).
The hertz is a frequency measurement of how
many times per second something happens. One hertz is simply one time-per-second, and
it’s abbreviated 1 Hz. One kilohertz is one-thousand-times-per-second, and it’s abbreviated
1 kHz.
FREQOUT
digitally synthesizes tones.
The
FREQOUT
command applies high/low pulses
of varying durations that make a piezospeaker’s vibration more closely resemble natural
vibrations of music strings.
Example Program: StartResetIndicator.bs2
This example program makes a beep at the beginning of the program, then it goes on to
run a program that sends
DEBUG
messages every half second. These messages will
continue indefinitely because they are nested between
DO
and
LOOP
. If the power to the
BASIC Stamp is interrupted while it is in the middle of its
DO…LOOP
, the program will
start at the beginning again. When it starts over, it will beep again. You can simulate a
brownout condition by either pressing and releasing the
Reset
button on your board or
disconnecting and reconnecting your board’s battery supply.
√
Reconnect power to your board.
√
Enter, save, and run StartResetIndicator.bs2.
√
Verify that the piezospeaker made a clearly audible tone for two seconds before
the “Waiting for reset…” messages started to display in the Debug Terminal.