Shop OBEX P1 Docs P2 Docs Learn Events
boe bot bluetooth DO Loop Stuck — Parallax Forums

boe bot bluetooth DO Loop Stuck

M.J.H.M.J.H. Posts: 2
edited 2012-05-03 06:51 in Robotics
Hello guys


its a glad to join your forum


I have a problem with the (Do... LOOP until) command and the easy blutooth module. I want it to skip the loop and initialize the next subroutine when "0" is pressed , but my code is just sticking and didn't response to any key press. I will be very appreciated for a help.
my code:


' {$STAMP BS2}
' {$PBASIC 2.5}


RX PIN 2
TX PIN 0
Baud CON 84


myByte VAR Byte
character VAR Word
index VAR Word
dirChar VAR Word
counter VAR Byte








PAUSE 250
SERIN RX, Baud, [myByte]
myByte = 0


FOR index = 0 TO 99
READ index, character
SEROUT TX, Baud, [character]
NEXT


DO


SERIN RX, Baud, [dirChar]




IF (dirChar = "0") THEN
GOSUB rest


ELSEIF (dirChar = "2") THEN
GOSUB rflash


ENDIF
LOOP


rest:


LOW 2
LOW 10
PAUSE 20


RETURN




rflash:
DO
FOR counter = 0 TO 9
HIGH 2
HIGH 10
PAUSE 500
LOW 2
LOW 10
NEXT
PAUSE 500
LOOP UNTIL (dirChar = "0")
PAUSE 20


RETURN






Thank you all in advance

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-02 07:36
    Your question doesn't make sense. Please clarify. You say you want the code to "skip the loop" and "initialize the next subroutine", but the only things after the DO / LOOP are the two subroutines "rest" and "rflash" which are already called from within the DO / LOOP. How about backing up a step, avoiding getting lost in the detail, and describing first what you're trying to accomplish overall, what the data looks like, etc.
  • M.J.H.M.J.H. Posts: 2
    edited 2012-05-03 04:23
    Thank you for your respond Mr.Green & sorry for not make it clear.


    my aim is to program a bluetooth controlled Traffic light .


    so that when the situation is normal the traffic light work normal.


    and when there is an emergency the traffic light should flash the red lamp.


    what I have posted earlier was only a small sample of what I have tested before but unfortunatly doesn't work.


    and what I am asking about is if I press 2 then the rflash subroutine will be initialized but when I press 0 the rflash mode will continue running(infinite loop) and the rest mode will never be energized.


    I am looking forward for an answer.






    thank you & all the best.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-05-03 06:51
    I think the problem is that your rflash routine expects that new commands will magically appear from Bluetooth while it is doing its flashing. That's not the way it works. SERIN only reads incoming characters when it's actually executing and, when it's executing, the Stamp can't do anything else (like listen for incoming characters). While rflash is executing, any incoming characters are being ignored.

    I don't think you can flash the emergency lamp the way you want ... with the Stamp automatically flashing it while waiting for a new command. The only way this would work is for the PC to send a "emergency lamp on" / "emergency lamp off" command. The Stamp basically waits for a command, does it, then goes back immediately to wait for another command.

    The only way you could do what you want ... doing something while the Stamp is still "listening" for Bluetooth data ... is to use some kind of external serial buffer that can receive data from Bluetooth while the Stamp is doing other things ... something like this.
Sign In or Register to comment.