Shop OBEX P1 Docs P2 Docs Learn Events
Combine Moving Backward and Flashing LEDs Commands — Parallax Forums

Combine Moving Backward and Flashing LEDs Commands

IllusIllus Posts: 2
edited 2010-12-04 22:10 in BASIC Stamp
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!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-01 13:24
    As you've seen, you cannot combine these the way you're trying to do it. The reason is that each of these routines (move backwards and blink LED) assumes that it has control of the Stamp for a considerable period of time. The blink routine takes about 20 seconds to execute while it's blinking the LED and the Stamp can't do anything else at the same time.

    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.
  • ercoerco Posts: 20,256
    edited 2010-12-01 13:29
    Plenty of things to fix here.

    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!
  • IllusIllus Posts: 2
    edited 2010-12-04 22:10
    Thank you! your suggestions really help!
Sign In or Register to comment.