Radio Shack TRS-80 Model 100 Basic Manual page 153

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

You can play the middle C scale by entering the following program:
10 FOR I = 1 TO 8
20 READ N : SOUND N, 30
30 NEXT I
a0
DATA
a687,a18a,3728,3516
50 DATA
313a,2783,2a8a,23a8
Execute the program to hear the familiar scale. This program reads eight notes from
the data statements and plays them for approximately .6 seconds each. The numbers in
the data statements correspond to C, D, E, F, G, A, B and C respectively and were
taken from the preceding table.
Experiment #3 Play a Melody
Referring to the table above. it is rather easy to write a BASIC program to play
melodies.
Clear memory using the NEW command and enter the following program:
10 READ N,L
20 IF N=0 THEN END
30 SOUND N, L*20
a0
GOTO 10
100 DATA
a687,
1
,a687,
1
,a687,
1 ,6268,1
110 DATA 5586,1 ,5586,1 ,6268,2,3728,1
120 DATA 3728
t1
,a18a
Ii
,a18a
Ii
,a687 ,a
130 DATA 0,0
Execute the program and you will hear the familiar Old MacDonald's Farm melody.
Line 18 The note N and the length L are read from the DATA statements. N is the
frequency specifier for the note, and L is the number of beats.
Line 28 A test for the end of the music is made. If the frequency specifier N is zero,
the .program ends. Otherwise, the note is played in the next statement.
Line 38 The SOUND statement plays the note for the desired number of beats. The
beat length is approximately
20
*
30
=
600 milliseconds
=
.6 seconds.
Line 48 Execution jumps back to Line 10 to read the next note.
Lines 188 - 128 Each note is defined by two numbers: Nand L. The frequency
specifier N is taken from the table above for the desired musical notes.
147

Advertisement

Table of Contents
loading

Table of Contents