boe bot bluetooth DO Loop Stuck
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
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
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.
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.