setting up a time statement
sambeaux
Posts: 3
I am new to this programming. Im wanting a program to do this: if an input goes low for 10 minutes I want to output a low at another pin. Can someone get me in the right direction. Ive read about the pause command but in milliseconds it would need 600000 milliseconds in 10 minutes and I believe a pause will only count to 65000. thanks very much...
Comments
Here's a routine that will wait until an input has been low for 10 minutes (100 ms granularity) before making the alarm output low:
Wait_For_10m:
· timer = 0
· DO
··· timer = (timer +·AlarmIn) * AlarmIn
··· PAUSE 100
· LOOP UNTIL (timer = 6000)
· AlarmOut = Active
· RETURN
There's a bit of a trick here: the value of timer will get incremented as long as the AlarmIn pin is high (1); if the pin goes low then timer gets cleared (because we ould be multiplying by zero), forcing the AlarmIn pin to stay high for the entire period.· I've used this technique in a commercial product I developed using a BS2 before my employment at Parallax.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
' {$STAMP BS2}
' {$PBASIC 2.5}
TimerLoop VAR Byte 'Create a variable for the timer loop
LoopCount CON 10 'Set number of iterations for the loop
Minute CON 60000 '1 minute = 60000 milliseconds
Init:
TimerLoop = 1
FOR TimerLoop = 1 TO LoopCount
PAUSE Minute
DEBUG "Loop ", DEC TimerLoop, CR 'For debugging loop, gives visual output, remove or comment out for final code
NEXT