XBRAT using PS2 AND SHARP sensor

I need help exiting a certain loop (DEFCON) which controls one of my BRATs air-soft guns. I use the PS2 controller to manoeuvre BRAT and to enter this routine, however when I try to exit this loop nothing seems to happen! I tried using the same method of exiting the loop as I used to enter it. The code below is what I’m using now.

[code]PS2Input:
.
.
.
IF (DualShock(2).bit7 = 0) and LastButton(1).bit7 THEN ;Square Button test
if (exit = FALSE) then
exit = TRUE
else
exit = FALSE
endif
ENDIF

.
.
.
retun

DEFCON:

while exit = 0

	gosub PS2Input
	
	if(pos = 1) then
		scandir = 0
	elseif(pos = -1)
		scandir = 1
	endif

	if (scandir = 1) then
		pos = pos + 2
	elseif(scandir = 0)
		        pos =  pos - 1
	endif

	hservo[head \ pos * 12000 \ 100]
	
	pause 3000						;pause program for a moment
	
	serout s_out,i9600,"scandirection: ", hex scandir,13]
	serout s_out,i9600,"pos: ", sdec pos,13]
	
	gosub readir

	if(pos > 0) then
		scandir = 0
	elseif(pos < 0)
		        scandir = 1
	endif

goto DEFCON
wend
goto main[/code]

A couple of quick things. One I assume TRUE and FALSE are defined.

Also In your DEFCON loop, I think the “goto DEFCON” line just before the WEND may be screwing stuff up. Not sure, but I would try removing it and see if that helps.

Kurt

Thanks for reply, and yes true and false are defined

Now I have changed the code yet it’s still not working. It doesn’t respond to the button commands whilst in this loop for some reason? it does respond, however, whilst in the ‘main’ of the program! what could the problem be?

Is this a cut and paste of the actual code? I see a misspelled “return” statement.

no it is not, I wrote the whole thing myself.

I think he was asking, is this the exact code from your program (i.e. did you cut and paste it directly from your program…).

If so the return statement just above DEFCON is misspelled. Since it was in column 1, it would be taken as a label and the code would simply fall through into DEFCON.

Kurt

I’m sorry for not being clear, what I meant to say was I did not cut and paste this from my code, rather I typed it straight in. However I have now managed to solve this issue but thanks for the suggestions.

What was the problem? It would be nice to share with everyone, in case someone else runs into the same issue.