Serial Comm. & Inputs
Brakkaroo
Posts: 3
O.K. I am trying to send serial communication from one stamp to another. Attached are both
pieces of code that work fine individually but have no desire to be put together. Just in case
I forget thanks for trying to help. Like I said when I try putting the button command with its
loop to count the # of contacts and the serial out command together the best I have seen is
the same message with every contact. Suggestions and comments greatly appreciated, A
thousand Thank You's.
' {$STAMP BS2}
This is the button counter
BtnWrk VAR Byte
cnt VAR Byte
punk VAR Word
Loop:
punk = punk+1
BUTTON 0,0,255,250,BtnWrk,0,NoPress
cnt = cnt+1
PAUSE 250
GOTO Loop
NoPress:
IF punk=2000 THEN GO
GOTO Loop
GO:
DEBUG CLS
DEBUG DEC cnt
cnt = 0
punk = 0
GOTO Loop
This is the code that properly sends the message. Hey thanks
' {$STAMP BS2}
BtnWrk VAR Byte
cnt VAR Byte
Loop:
BUTTON 2,0,255,250,BtnWrk,0,NoPress
cnt = cnt+1
GOTO Brain
NoPress:
GOTO Loop
GO:
SEROUT 1\0, 16468, [noparse][[/noparse]"HELLO!",CR]
PAUSE 250
GOTO Loop
Brain:
IF cnt = 1 THEN GO
IF cnt = 2 THEN Ear
IF cnt = 3 THEN Nose
Nose:
SEROUT 1\0, 16468, [noparse][[/noparse]"ByeBye!",CR]
PAUSE 250
cnt = 0
GOTO Loop
Ear:
SEROUT 1\0, 16468, [noparse][[/noparse]"DUH",CR]
PAUSE 250
GOTO Loop
pieces of code that work fine individually but have no desire to be put together. Just in case
I forget thanks for trying to help. Like I said when I try putting the button command with its
loop to count the # of contacts and the serial out command together the best I have seen is
the same message with every contact. Suggestions and comments greatly appreciated, A
thousand Thank You's.
' {$STAMP BS2}
This is the button counter
BtnWrk VAR Byte
cnt VAR Byte
punk VAR Word
Loop:
punk = punk+1
BUTTON 0,0,255,250,BtnWrk,0,NoPress
cnt = cnt+1
PAUSE 250
GOTO Loop
NoPress:
IF punk=2000 THEN GO
GOTO Loop
GO:
DEBUG CLS
DEBUG DEC cnt
cnt = 0
punk = 0
GOTO Loop
This is the code that properly sends the message. Hey thanks
' {$STAMP BS2}
BtnWrk VAR Byte
cnt VAR Byte
Loop:
BUTTON 2,0,255,250,BtnWrk,0,NoPress
cnt = cnt+1
GOTO Brain
NoPress:
GOTO Loop
GO:
SEROUT 1\0, 16468, [noparse][[/noparse]"HELLO!",CR]
PAUSE 250
GOTO Loop
Brain:
IF cnt = 1 THEN GO
IF cnt = 2 THEN Ear
IF cnt = 3 THEN Nose
Nose:
SEROUT 1\0, 16468, [noparse][[/noparse]"ByeBye!",CR]
PAUSE 250
cnt = 0
GOTO Loop
Ear:
SEROUT 1\0, 16468, [noparse][[/noparse]"DUH",CR]
PAUSE 250
GOTO Loop
Comments
http://www.parallax.com/ProductInfo/Microcontrollers/BASICStampSoftware/tabid/441/Default.aspx
The first two lines of you code should be
' {$STAMP BS2}
' {$PBASIC 2.5}
Two things that will improve your code, the first is to use GOSUB rather than GOTO, remember all sub routines should have a RETURN. The second is the addition of·an extra BUTTON instruction that sits waiting for the very first press. The rest of your code looks absolutly fine. Try this for the button routine.
DO
· BUTTON 0, 0, 255, 250, btnWrk, 1, Press1·· 'wait for the· first button press then jump into the next do loop and start counting
LOOP
DO WHILE punk<500
· PAUSE 10
· BUTTON 0, 0, 255, 250, btnWrk, 0, No_Press
· cnt=cnt+1
· Press1:
· DEBUG HOME,DEC cnt +1
· punk=0
· No_Press:
· punk=punk+1
LOOP
ON cnt GOSUB GO,Ear,Nose··· ' jump to subroutine dependent on the value of count
Jeff T.
EDIT: sorry Stephen I answered this before I read your response in the duplicate thread.
Post Edited (Unsoundcode) : 12/31/2007 4:32:31 PM GMT