Combine Moving Backward and Flashing LEDs Commands
I'm new to the Boebot and I've been trying to combine Moving Backward and Flashing LEDs commands by subroutine; but I still haven't been able to got it done. Any one can help with me with this? I'm using PBasic 2.5. Stamp BS2
Here's my command:
' {$STAMP BS2}
' {$PBASIC 2.5}
pulseCount VAR Word
FOR pulseCount = 1 TO 200
GOSUB Backward
NEXT
Backward:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
GOSUB LED
RETURN
LED:
FOR counter = 1 TO 20
DO
HIGH 10
PAUSE 500
LOW 10
PAUSE 500
LOOP
NEXT
RETURN
Appreciate your help!
Here's my command:
' {$STAMP BS2}
' {$PBASIC 2.5}
pulseCount VAR Word
FOR pulseCount = 1 TO 200
GOSUB Backward
NEXT
Backward:
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
GOSUB LED
RETURN
LED:
FOR counter = 1 TO 20
DO
HIGH 10
PAUSE 500
LOW 10
PAUSE 500
LOOP
NEXT
RETURN
Appreciate your help!
Comments
On a Propeller, you could do this because there are 8 separate processors that can function independently, so one can blink the LED and one can control the servo and send out a control pulse every 20ms. On a Stamp, there's only one processor.
The way you could do this would be to use the PAUSE 20 in the movement routine as a kind of clock tick. It takes 20ms and you could keep a counter that increments every 20ms, once per loop. You'd need to add some logic to see if the counter gets to 25. That would be roughly 1/2 second. If the count reaches 25, you could reset the counter to zero and toggle the state of the LED which would end up blinking on-off-on-off changing every 1/2 second.
To move your servo motors, you need a steady stream of PULSOUTs and PAUSE 20s. After each PAUSE, you execute a 20-second LED flash routine, which definitely interrupts the PULSOUT stream.
Besides that, you have a DO loop inside your FOR/NEXT loop. Not sure what your intention was there, that's TWO LOOPS, Lautrec! (Bad pun, http://www.lautrec.info/)
Try this for starters:
' {$STAMP BS2}
' {$PBASIC 2.5}
outer VAR byte
inner var byte
for outer=1 to 30' start outer loop, execute 30 times
FOR inner = 1 TO 20' start inner loop to drive servo, 20 loops=~ half second
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
next' end inner loop
toggle 10' toggle LED to flash
next' end outer loop
Edit: Mike beat me to it!