Help with Setting timer and varying time of pulsout
Bray12
Posts: 3
I'm programming an automatic gate model. I need the gate to open on input of IN3, stay open for 10 seconds and then close. The program below does this, however I would like the servo to move slower. When I introduce a second variable to the subroutine e.g" for counter = 950 to 400, pulsout 13, counter" it results in the subroutine taking longer, as you would expect. I don't know how to slow the servo down without effecting the duration of the subroutine.
Any help is really appreciated, thanks.
' {$STAMP BS2}
' {$PBASIC 2.5}
closetimer VAR Word
counter VAR Word
DO
IF ( IN3 = 1) THEN
GOSUB fob_open
ENDIF
LOOP
'
(subroutines)
fob_open:
FOR closetimer = 1 TO 300
PULSOUT 13, 400
PAUSE 20
NEXT
PULSOUT 13,950
Any help is really appreciated, thanks.
' {$STAMP BS2}
' {$PBASIC 2.5}
closetimer VAR Word
counter VAR Word
DO
IF ( IN3 = 1) THEN
GOSUB fob_open
ENDIF
LOOP
'
(subroutines)
fob_open:
FOR closetimer = 1 TO 300
PULSOUT 13, 400
PAUSE 20
NEXT
PULSOUT 13,950
Comments
Thank you very much. Your help was spot on. Here's what worked:
' {$STAMP BS2}
' {$PBASIC 2.5}
opentimer VAR Word
closetimer VAR Word
counter VAR Word
DO
IF ( IN3 = 1) THEN
GOSUB fob_open
ENDIF
LOOP
'
(subroutines)
fob_open:
FOR opentimer = 0 TO 548 STEP 4
PULSOUT 13, 950 - opentimer
PAUSE 20
NEXT
FOR counter = 1 TO 420
PULSOUT 13, 400
PAUSE 20
NEXT
FOR closetimer = 400 TO 970 STEP 4
PULSOUT 13, closetimer
PAUSE 20
NEXT
RETURN
Felt great watching it work! My next step is to introduce a sensor to allow the gate to open on approach. I plan to add a new subroutine, very similar to the last, that's called on initiation of an input similar again to the existing IN3. I have a fair idea of what to try as I've completed "what's a micro controller" and built the BOE bot a couple of years ago, but I'm sure I will be in need of more support when the code is assembled and I've not managed to get it working!
Thanks again for your help,
Jim.