I tried this, but now I get no result at all:
j var word ' timing loop count for 3sec record timing
k var word ' timing loop count for 57sec wait timing
Mainloop:
if CYCLE = 0 then goto Mainloop ' do not do any recording
if cycle = 1 then gosub recording ' do the 3/57 record cycle
goto mainloop
Recording:
low RECPB ' Low Rec PB to start recording
Pause 500 ' start recording for 3 seconds
high RECPB ' High Rec PB after recording start
for j = 1 to 3000 ' Loop count for rec timing
pause 1
next j
low RECPB ' Low Rec PB to stop recording
Pause 500 ' Stop recording after 3 seconds
high RECPB ' High Rec PB after recording Stop
for k = 1 to 10000 ' **Pause for 57 seconds and repeat cycle.
pause 1 '
next k
return
End
Not sure to be honest...
How is the switch wired? Pin to GND with pullup or pin to Vdd with pulldown?
Give this a try:
Code:DEFINE OSC 4 RECPB var GPIO.4 ' Assign name "RECPB" to GPIO 4 OUTPUT CYCLE var GPIO.0 ' Assign name "CYCLE" to GPIO 0 INPUT TRISIO.4 = 0 ' GPIO.4 as output ANSEL = 0 CMCON0 = 7 OPTION_REG.7 = 0 ' Enable individual pullups WPU.0 = 1 ' Enable weak pullup on GPIO.0 Mainloop: IF Cycle = 1 THEN ' do the 3/57 record cycle RECPB = 0 ' Low Rec PB to start recording Pause 500 ' start recording for 3 seconds RECPB = 1 ' High Rec PB after recording start PAUSE 3000 RECPB = 0 ' Low Rec PB to stop recording Pause 500 ' Stop recording after 3 seconds RECPB = 1 ' High Rec PB after recording Stop PAUSE 10000 ENDIF GOTO Mainloop End
Thanks very much Henrik. That works . . . . too good! I can't switch off the cycle, it just keeps running.
The switch pulls pin to ground. (In real life I use this in my car where I have a relay that closes when the engine runs)
Are you 100% sure you have the switch on the correct pin? Have you measured the voltage on the pin with the switch in both positions? 0V in one position, 5V (or whatever the supply voltage is) in the other.
I am sure the pin is wired correct and I can measure it going from 0 to 4.8V . Let me look some more . . . . . . .
' Name : Henrik.pbp
' Compiler : PICBASIC PRO Compiler 3.1.6.2
' Assembler : PM or MPASM
' Target PIC : 12F types
' Hardware : Non specific
' Oscillator : internal
#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
#ENDCONFIG
DEFINE OSC 4
RECPB var GPIO.4 ' Assign name "RECPB" to GPIO 4 OUTPUT
CYCLE var GPIO.0 ' Assign name "CYCLE" to GPIO 0 INPUT
TRISIO.4 = 0 ' GPIO.4 as output
ANSEL = 0
CMCON0 = 7
OPTION_REG.7 = 0 ' Enable individual pullups
WPU.0 = 1 ' Enable weak pullup on GPIO.0
Mainloop:
IF Cycle = 1 THEN ' do the 3/57 record cycle
RECPB = 0 ' Low Rec PB to start recording
Pause 500 ' start recording for 3 seconds
RECPB = 1 ' High Rec PB after recording start
PAUSE 3000
RECPB = 0 ' Low Rec PB to stop recording
Pause 500 ' Stop recording after 3 seconds
RECPB = 1 ' High Rec PB after recording Stop
PAUSE 10000
ENDIF
GOTO Mainloop
End
Bookmarks