i just have a button, led and a resistor, basic stamp 2, pbasic 2 i think. my friend was the one who asked me for help and i tried to give him some very easy and small codes but i don't know if they'll work since i've never used basic stamp and don't have any near me that i can try out.
Maybe I'm missing something, but this seems pretty easy.
' {$STAMP BS2}
' {$PBASIC 2.5}
Trigger PIN 0
LED PIN 1
Main:
DO WHILE (Trigger = 0)
' wait for button press
LOOP
HIGH LED
PAUSE 5000
LOW LED
DO WHILE (Trigger = 1)
' wait for release
LOOP
GOTO Main
If you want early off but 5s max you can do it like this:
' {$STAMP BS2}
' {$PBASIC 2.5}
Trigger PIN 0
LED PIN 1
timer VAR Word
Main:
DO WHILE (Trigger = 0)
' wait for button press
LOOP
HIGH LED
FOR timer = 1 TO 500
PAUSE 10
IF (Trigger = 0) THEN Exit
NEXT
LOW LED
DO WHILE (Trigger = 1)
' wait for release
LOOP
GOTO Main
Adding to what JonnyMac said, here is the same thing except the state of the button is defined as a constant. Now the code can be transferred to the Professional Development board more easily.
' {$STAMP BS2}
' {$PBASIC 2.5}
trigger PIN 0
LED PIN 1
buttonPressed CON 0 'state of trigger when pressed
Main:
DO WHILE (trigger <> buttonPressed) 'wait for button
LOOP
HIGH LED 'turn it on
PAUSE 5000 'five seconds
LOW LED 'then off
DO WHILE (trigger = buttonPressed) 'wait for release
LOOP
GOTO Main
Comments
But for goodness sake, download basic 2.5 so you have the PIN statement!
If you want early off but 5s max you can do it like this: