In this lesson you will learn how to create a wide variety of sounds, simulate events
using the built-in random number function, and cause apparent movement (animation)
on the display.
Lesson
#12
Sound & Simulation
Experiment
#1
Beep your Beeper!
You can use the built-in speaker to create sounds of many types: beeps, sirens,
whistles, clicks, and so on.
Sound can be used in a BASIC program to draw attention to some event - the
OCCurrence
of
an error, for example.
It
might also be used
to
liven-up a program by
adding noises to indicate movement. You might also want
to
use your Computer to
create music. All these uses
of
sound are fairly easy on the Model 100
as
you'll find
in the following experiments.
You have already seen that printing CHR$(7) will sound the
"bell"
character. Try it
now
to
recall the sound:
PRINT
CHR$(7)
~
Another way
to
make the same sound
is
to use the BEEP statement. Type:
BEEP
CEH.ml
and
you will hear the same sound. To verify that the sounds are identical, enter
PRINT
CHR$(7) :
BEEP
and you will hear two beeps in succession.
You might want
to
use sound
as
a sort
of
warning. Try this:
FOR
1=1
TO
10 :
BEEP
:
NEXT
I
~
You can also vary the tone and duration
of
the sound using another statement
as
shown in the next experiment.
Experiment
#2
Sound
OfT!
Create a tone by entering the following command:
SOUND
5588,100
You should have heard a tone lasting approximately two seconds and having a
frequency of 440 hertz. Increase the frequency of the tone
by
entering:
SOUND
4151100
or lower the tone by entering:
SOUND
15800,100
145