Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP basic stamp!!!!

Status
Not open for further replies.

jhill44

Electrical
Joined
Apr 13, 2009
Messages
1
Location
US
working on an autonomous refrigerator and im running into a wall!!! seems to be running a continuous loop and im not to sure how to get out of it. i am trying to initiate the autonomous movement with a universal remote, then it runs through a series of obstacle avoidance subroutines..... i placed an if....then statement at the beginning of the program which states if button_code and device_code are pressed (my designated stop button) then so to sub stop_bot. although i feel like this should work it doesn't. ive tried a do.....loop until command and that doesnt seem to be doing the trick either. any help would be great for i am on a deadline to finish this project relatively soon. here is a copy of the code i have written............


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

DEBUG "program running"

'------------[variables]-----------------------------------------------

irdetectleft VAR BIT
irdetectright VAR BIT
irdetectcenter VAR BIT
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

COMMAND_030:
SEROUT 14, 16468, [30]
poop:
SERIN 15, 16468,1000,main, [device_code, button_code]
DEBUG "button code =", DEC Button_Code," Device Code =",DEC Device_code," ", CR
DEBUG " ",CR
DEBUG "____________________________",CR
DEBUG HOME
IF Button_code = 21 AND Device_code = 1 THEN obstacle_avoidance
IF BUTTON_code = 101 AND device_code = 1 THEN STOP_bot
GOTO poop



'----------[subroutines]----------------------------------------------



obstacle_avoidance:
DO
FREQOUT 8, 1, 38500
irdetectleft = IN9

FREQOUT 2,1, 38500
irdetectright = IN0

FREQOUT 3,1, 38500
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]
SEROUT 16, 8276, ["!b1E", CR]
RETURN

turn_left:
PAUSE 20
SEROUT 16, 8276, ["!A14", CR]
SEROUT 16, 8276, ["!b14", CR]
RETURN

turn_right:
PAUSE 20
SEROUT 16, 8276, ["!A1E", CR]
SEROUT 16, 8276, ["!b1E", CR]
RETURN

back_up:
PAUSE 20
SEROUT 16, 8276, ["!a1E", CR]
SEROUT 16, 8276, ["!B1E", CR]
RETURN

STOP_bot:
PAUSE 20
SEROUT 16, 8276, ["!A00", CR]
SEROUT 16, 8276, ["!B00", CR]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top