The application is to trigger a camera shutter.
In one mode the shutter is triggered continuously until the camera battery runs out, whether the PIR is attached or not.
In the other mode the shutter is triggered continuously for one minute every time the PIR is triggered.
In practice, when I want to use the PIR, I set up the camera and the PIR, turn on the PIR and check that its LEDs are on, and then turn on the Picaxe.
The first readadc in CheckPIR should recognise that the the PIR is on and fall through into the testPIR loop.
If the first readadc does not recognise that the PIR is on, the program jumps to NoPIR and shoots continuously.
The program often missed the fact that the PIR was turned on and jumped to NoPIR.
Since I have added the pause 2000 (marked with the asterisks) the first readadc always recognises the signal from the PIR. So far.
I don't know why.If it works, and doesn't let the smoke escape, I am content.
This is the relevant bit of code.
'Programme
init:
input 1
setfreq m8 'set Picaxe frequency to 8MHz
start:
pwmout 2,52,105 '38kHz for 8MHz clock speed
low 4 'IR LED off
'===============================
'If the program is started with the PIR turned on and
'triggered, the program will loop, looking for a
'response from the PIR.
CheckPIR:
pause 2000 '****************************
readadc 1, avalue
if avalue < lowval then NoPIR 'No signaldetected from PIR.
'Commence continuous shooting.
'===============================
PIR:
'===============================
'Do not shoot unless triggered by a signal from the PIR
testPIR:
readadc 1, avalue
if avalue < lowval then testPIR
'================================
'Shoot at maximum rate for ~ one minute
for i = 1 to 300
gosub pulse_stream
pause 200 ' ' ~0.1 seconds between shots
next i
goto testPIR
'================================
'Normal continuous shooting
NoPIR:
gosub pulse_stream
pause 200 '~0.1 seconds between shots
goto NoPIR