any one able to help me get out of this continuous loop?. first of all let me explain the circumstance: i am making a bot base that is capable of full obstacle avoidance using the ir sensors that came with the boe-bot kit. in addition i am using a device called the ir control freak which receives ir signals from a common household remote control. the program seems to be working fine, when i power up the stamp nothing happens until i push the power button on the remote. however when i push the stop button (button code 101), the program seems to be stuck in the do. . . .loop statment and the bot will not stop. i added some simple comments to give an idea of what everything is doing throughout the program. i have been trying to figure out if i should use the loop until function, or even the exit function. however i have been unsuccessful. is there some way that i could assign a bit variable to go high when i push the ok button (button code 101) on the remote, then force the do. . . loop to end based on the state of said bit?? my apologies for the lengthy post, just wanted to make sure that i hadnt left anything out. any help that you could offer would be greatly appreciated. thanks for your time matthew fitzgerald
p.s. i wasnt able to load attachment to this post, so the code is as follows: sorry for any inconvenience!
[code]’ {$STAMP BS2}
’ {$PBASIC 2.5}
'------------[variables]-----------------------------------------------
irdetectleft VAR Bit 'left sensor
irdetectright VAR Bit 'right sensor
irdetectcenter VAR Bit 'center sensor
BUTTON_CODE VAR Byte 'Infrated Button Code
DEVICE_CODE VAR Byte 'Infrared Device Code
'------------[main routine]--------------------------------------------
'***************************
'* MAIN PROGRAM *
'***************************
MAIN:
GOSUB COMMAND_030 'Send the Remote control Command to Infrated Control Freak
GOTO MAIN
'----------[subroutines]----------------------------------------------
COMMAND_030:
SEROUT 14, 16468, [30] 'ir control freak reading remote i/o
remote:
SERIN 15, 16468,1000, main, [device_code, button_code] 'ir control freak reading remote i/o
DEBUG “button code =”, DEC Button_Code," Device Code =",DEC Device_code," ", CR
DEBUG "pin 13 = ", CR
DEBUG " ",CR
DEBUG “____________________________”,CR
DEBUG HOME
IF Button_code = 21 AND Device_code = 1 THEN GOSUB obstacle_avoidance ’ Button code 21 is power button
IF button_code = 101 AND device_code = 1 THEN stop_bot ’ Button code 101 is ok button
GOTO remote
obstacle_avoidance:
DO
FREQOUT 8, 1, 38500 'ir sensor
irdetectleft = IN9
FREQOUT 2,1, 38500 'ir sensor
irdetectright = IN0
FREQOUT 3,1, 38500 'ir sensor
irdetectcenter = IN4
IF (irdetectcenter = 0) THEN
GOSUB back_up
ELSEIF (irdetectleft = 0) THEN
GOSUB turn_right
ELSEIF (irdetectright = 0) THEN
GOSUB turn_left
ELSE
GOSUB forward_pulse
ENDIF
LOOP
forward_pulse:
PAUSE 100
SEROUT 16, 8276, “!A1E”, CR] '!A and !b indicate channel on motor controller (external power amp),
SEROUT 16, 8276, “!b1E”, CR] '1E is hx value (0-127) that controls speed of motors
RETURN
turn_left:
PAUSE 100
SEROUT 16, 8276, “!A1E”, CR]
SEROUT 16, 8276, “!b14”, CR]
RETURN
turn_right:
PAUSE 100
SEROUT 16, 8276, “!A14”, CR]
SEROUT 16, 8276, “!b1E”, CR]
RETURN
back_up:
PAUSE 100
SEROUT 16, 8276, “!a1E”, CR]
SEROUT 16, 8276, “!B1E”, CR]
RETURN
Stop_bot:
PAUSE 100
SEROUT 16, 8276, “!A00”, CR]
SEROUT 16, 8276, “!B00”, CR]
GOTO remote[/code]