PSU controller - program help
Here is my program:
What happens is that the basic stamp stops executing code towards the beginning. I have to hold the "on" switch down to keep the PSU on. Can anyone help me? I can't find the problem.
' {$STAMP BS2}
' {$PBASIC 2.5}
a: 'label a
HIGH 0:LOW 1 'hold PSU off and red LED off
IF IN15=1 THEN 'if on button pressed
LOW 0 'turn PSU on
PAUSE 1000 'wait one second
ELSEIF IN14=1 OR IN13=0 THEN 'else, if off button is pressed or ok signal absent
GOSUB b 'goto sub label b
GOTO a 'goto a
ELSE 'else
GOTO a 'goto a
ENDIF 'end if-then statement
GOTO a 'goto a
b: 'sub label b
IF IN13=0 THEN 'if ok signal absent
HIGH 0 : HIGH 1 'turn PSU off and turn red LED on
END 'stop running
ELSEIF IN13=1 THEN 'if ok signal is present
LOW 0 : LOW 1 'turn red LED off and PSU on
ENDIF 'end if-then statement
RETURN 'go back to main program
What happens is that the basic stamp stops executing code towards the beginning. I have to hold the "on" switch down to keep the PSU on. Can anyone help me? I can't find the problem.

Comments
It looks like if the button is pressed it turns on the power supply, waits a second and starts over "GOTO a" where it turns the power supply back off.
Can you expain what you want it to do?
EDIT:
the program I was basing my code on, which does not support coding BASIC, had a BASIC viewer which, on the program, gave this: If I edited that, it should say this right?:
' {$STAMP BS2} ' {$PBASIC 2.5} main: a: HIGH 0 LOW 1 b: IF IN15=1 THEN c GOTO b c: LOW 0 PAUSE 1000 d: IF IN13=0 THEN e HIGH 0 HIGH 1 END e: IF IN14=1 THEN a GOTO d GOTO a' {$STAMP BS2} ' {$PBASIC 2.5} a: 'label a HIGH 0:LOW 1 'hold PSU off and red LED off IF IN15=1 THEN 'if on button pressed LOW 0 'turn PSU on PAUSE 1000 'wait one second c: IF IN14=1 OR IN13=0 THEN 'else, if off button is pressed or ok signal absent GOTO b 'goto label b ELSE GOTO c 'goto c watch off button and ok signal again ENDIF ENDIF 'end if-then statement GOTO a 'goto a b: 'b beginning of end, program will end soon HIGH 0 'turn PSU off IF IN13=0 THEN 'if ok signal absent HIGH 1 'turn red LED on PAUSE 2000 'leave LED on for 2 seconds ELSE LOW 1 'turn red LED off (was it ever on?) ENDIF 'end if-then statement ENDOkay, I don't use Basic Stamps anymore but I think this will do what you want. I really don't like posting code I haven't tested (nor compiled) so let me know if this works. Did you want the LED to stay on? I don't think you can have the LED stay on unless you leave the program running. As it is now, the LED will stay on for two seconds. I think you could use the same button for both on and off if you wanted to. Just use the same pin number.Edit: I think the formatting is okay now.
This should let you turn the PSU on and off with the program waiting for the on button after it has been turned off.
This program always stays running. If the ok signal is lost the LED will come on and the PSU will turn off. When the PSU is turned on again and it finds the ok signal, then the LED will be turned back off.
So if the LED is on, it means the last time the power supply was turned off was because of the ok signal had been lost.
' {$STAMP BS2} ' {$PBASIC 2.5} a: 'label a HIGH 0 'hold PSU off IF IN15=1 THEN 'if on button pressed LOW 0 'turn PSU on PAUSE 1000 'wait one second c: IF IN14=1 OR IN13=0 THEN 'if off button is pressed or ok signal absent GOTO b 'goto label b ELSE LOW 1 'make sure LED is off GOTO c 'goto c watch off button and ok signal again ENDIF ENDIF 'end if-then statement GOTO a 'goto a b: 'b prepare to wait for on button again HIGH 0 'turn PSU off IF IN13=0 THEN 'if ok signal absent HIGH 1 'turn red LED on ENDIF 'end if-then statement PAUSE 1000 'wait a second so on and off button can be shared GOTO a ENDAgain, this program will let you use the same button for both on and off if you wanted.
No, no, no. It just means you need more practice. Like so many things, programming gets easier the more you pactice at it.
And, you're very welcome.