sound_examples.bas (1724Bytes)
There are three commands in Picaxe Basic that you can use for making sounds/music on the Picaxe. I posted my code as a file attachment, and there are some examples from the code below.
Note that on the Picaxe-08 models, you need to use Output 2 for the play and tune commands.
The 'play' command lets you play one of a few stored music samples.
Available tunes are:
0 - Happy Birthday (All parts)
1 - Jingle Bells (All M & X2 parts)
2 - Silent Night (08M only)
3 - Rudolph the Red Nosed Reindeer (08M only)
Example:
bday:
play soundpin, 0 'plays pre-set tune 0-3. Happy Birthday is all the Picaxe 28x1 has
return
The 'tune' command lets you encode a series of musical notes. The Picaxe Editor includes a Tune Wizard that can help, but for the two I've created, I rolled my own. If you can find the musical notes for a tune you want online somewhere, you can code the song for the Picaxe.
Example:
encounter:
'To get the spaceships' attention prior to their arrival at Devil's Tower,
'the five notes the scientists play are G, A, F, (octave lower) F, C.
'When they arrive at the tower and are attempting communication,
'the notes they play are B flat, C, A flat, (octave lower) A flat, E flat.
'Flat notes are the same as the sharp (#) of the previous note
tune soundpin,12,(7,9,5,37,192) 'plays Close Encounters tune
return
The 'sound' command is good for simple beeps and buzzes.
Examples:
buzzer:
sound soundpin,(237,10)
pause 100
sound soundpin,(247,10)
pause 100
sound soundpin,(177,10)
pause 10
low soundpin
return
rising:
let b0 = b0 + 1
sound soundpin,(b0,50)
pause 100
if b0 = 126 then return
endif
goto rising