12
PICAXE-08 ALARM PROJECT
revolution
© copyright 2002 - AXE102 Alarm Student Project Notes Version 1.1
Revolution Education Ltd. Email: [email protected] Web: www.rev-ed.co.uk
12
Supported by:
Testing the piezo connection.
After connecting the piezo it can be tested by a simple
program like this:
main:
sound 2,(65,100)
sound 2,(78,100)
sound 2,(88,100)
sound 2,(119,100)
goto main
This program would make the piezo (connected to
output pin 2) make 4 different sounds (value 65, 78, 88
and 119). If the piezo does not work check:
1) the sound value is between 0 and 127
2) the correct output pin number is being used in the program
3) all the solder joints are good
With the sound command, the first number provides the pin number (on projects pin2
is often used). The next number is the tone, followed by the duration. The higher the
tone, the higher the pitch of the sound (note that some sounders cannot produce very
high tones and so number greater than 127 may not be heard).
When using multiple sounds you may also include them all on the same line e.g.
sound 2,(65,100,78,100,88,100,119,100)
The following table shows some common notes with the appropriate sound value:
A(49), As(51), B(54), C(57), Cs(61), D(65), Ds(71), E(78), F(88), Fs(101), G(119)
The following BASIC program uses a for…next loop to produce 120 different sounds,
using variable b1 to store the sound value.
main:
for b1 = 1 to 120
start a for...next loop
sound 2,(b1,50)
make a sound, freq value from b1
next b1
next loop
end
The number stored in variable b1 is increased by 1 in every loop (1-2-3 etc.) Therefore by
using the variable name b1 in the tone position, the note can be changed on each loop.
The following program does the same task but backwards (counting down instead of
up).
main:
for b1 = 120 to 1 step -1 start a for...next loop
sound 2,(b1,50)
make a sound, freq value from b1
next b1
next loop
end
start
sound 2,(65,100)
sound 2,(78,100)
sound 2,(88,100)
sound 2,(119,100)