Specifications
BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 265
2
Figure I-4
the first frequency is the musical note itself, while the second is 8 Hz
lower. When sines mix, sum and difference frequencies are generated.
The difference frequency imposes an 8-Hz quiver (vibrato) on each
note. Subtracting 8 from the note frequency poses a problem when the
frequency is 0, because the BS2’s positive-integer math wraps around to
65530. Freqout would ignore the highest bit of this value and generate
a frequency of 32762 Hz rather than a truly silent pause. Although
humans can’t hear 32762 Hz, slight imperfections in filtering will cause
an audible noise in the speaker. To clean this up we use the expression
“(f-8) max 32768,” which changes 65530 to 32768. Freqout discards the
highest bit of 32768, which results in 0, the desired silent pause.
i var byte ' Counter for position in tune.
f var word ' Frequency of note for Freqout.
C con 523 ' C note.
D con 587 ' D note
E con 659 ' E note
G con 784 ' G note
R con 0 ' Silent pause (rest).
for i = 0 to 28 ' Play the 29 notes of the Lookup table.
lookup i,[E,D,C,D,E,E,E,R,D,D,D,R,E,G,G,R,E,D,C,D,E,E,E,E,D,D,E,D,C],f
FREQOUT 0,350,f,(f-8) max 32768
next
stop
10µF (both)
+
+
≥40Ω Speaker
(or 8Ω in series
with 33Ω resistor)
I/O pin
C1 C2
Notes:
C1 may be omitted for piezo speakers
C2 is optional, but reduces high-frequency noise
I/O pin
Driving a Speaker
1k
0.1µF 0.01µF
1k
Driving an Audio Amplifier
Amplifier
(e.g., Radio Shack
277-1008C)










