'Picaxe 18M2
'PIR Trigger for Witch chants
symbol PIR= B.7 `PIR sensor
symbol TENDA_OUT=B.3 `Tenda RXD `
symbol VERSE=b6
symbol Debounce=b8
symbol Retrigger_Delay=b9
symbol BAUD=T4800
symbol Wait_If_Busy=pinB.1 `Tenda Busy Line
Init: 'Staring point to setup all inputs, outputs and set variables
serout TENDA_OUT,BAUD, ($EF); 'STOP MP3 module
pause 500
serout TENDA_OUT,BAUD, ($E8) `set Tenda Volume
pause 500
;
Start:
Do Loop Until debounce=10
Do
serout TENDA_OUT, Baud, ($01) `play Track 1
pause 1000
readadc PIR, debounce
if debounce<1 then exit 'if PIR Trigger not detected then loop opening mp3
pause 1000
Debounce = Debounce +1
if Debounce>9 then Open_Chant 'if triggered go to opening chant
loop
Open_chant:
Gosub Clear_Debounce 'clear Trigger
Pause 1000
serout TENDA_OUT,BAUD,($02) 'play cackle,Track 2
do
if Wait_If_Busy=1 then serout TENDA_OUT,BAUD,($03) endif''watch for chant to end,play opening chant Track3
if Wait_If_Busy=1 then gosub Spellcast
loop
Spellcast:
random VERSE 'begin random selection of verses
VERSE=VERSE//$03-$09 'modulus to generate random mp3
serout TENDA_OUT,BAUD,(VERSE)
pause 1000
do
if Wait_If_Busy=1 then exit'watch for spellcast to end
loop
for Retrigger_Delay=1 to 75
pause 5000
next Retrigger_Delay
goto Start
Clear_Debounce:
Debounce=0
return