BUTTON command
philipad23
Posts: 44
Hi all...
I'm using the BUTTON command but it seems to have problem when some other commands are to be executed. I tried the following code:
Main:
DEBUG "2"
PAUSE 50
BUTTON Btn, 0, 200, 20, btnWrk, 0, if_press
DEBUG "1"
if_press:
GOTO Main
This works fine…But if I insert a SERIN command which is necessary for the code I am programming, I does not anything…
Main:
SERIN 16, 84, Timeout, [noparse][[/noparse]DEC a] ' Await serial data
WRITE 1,a
READ 1,b
DEBUG ?b
DEBUG "2"
PAUSE 50
BUTTON Btn, 0, 200, 20, btnWrk, 0, if_press
DEBUG "1"
if_press:
GOTO Main
timeout:
Anyone can help me?
I'm using the BUTTON command but it seems to have problem when some other commands are to be executed. I tried the following code:
Main:
DEBUG "2"
PAUSE 50
BUTTON Btn, 0, 200, 20, btnWrk, 0, if_press
DEBUG "1"
if_press:
GOTO Main
This works fine…But if I insert a SERIN command which is necessary for the code I am programming, I does not anything…
Main:
SERIN 16, 84, Timeout, [noparse][[/noparse]DEC a] ' Await serial data
WRITE 1,a
READ 1,b
DEBUG ?b
DEBUG "2"
PAUSE 50
BUTTON Btn, 0, 200, 20, btnWrk, 0, if_press
DEBUG "1"
if_press:
GOTO Main
timeout:
Anyone can help me?
Comments
Indeed, if your serial input routines ALWAYS times out for some reason, you will NEVER reach the BUTTON command. Add the following to your routine to check that:
timeout:
DEBUG "T. O. occurred"
and see if that's what's happening.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I make some changes to the code so the serin has 5 seconds until timeout but when I put a subroutine to the BUTTON command this is executed whether the button is pressed or not.
Main:
SERIN 16, 84,5000, Timeout, [noparse][[/noparse]DEC a] ' Await serial data
WRITE 1,a
READ 1,b
DEBUG ?b
DEBUG "2"
PAUSE 50
BUTTON Btn, 0, 200, 20, btnWrk, 0, if_press
if_press:
DEBUG "1"
GOTO Main
timeout:
DEBUG "timeout"
GOTO main
The DEBUG "1" is executed anyway
Do you know why?
BUTTON Btn, 0, 200, 20, btnWrk, 0, if_press
if_press:
DEBUG "1"
GOTO Main
So, when you press the Button, you are telling it to branch to if_press AND it does·so without because it's supposed to be a part of a Loop.· You need to tell it to try the button again if it wasn't pushed:
CheckButton:
· BUTTON Btn, 0, 200, 20, btnWrk, 0, if_press
· GOTO Check Button
if_press:
DEBUG "1"
GOTO Main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When you get 1st Place in the "Darwin Awards", you're a Winner & a Loser.
I know why, and you should too. Where else is the program going to go to?
The program logic is straight-line (with the exeception of the timeout routine), and non-stop. There is no other choice than to drop right through the entire program. Where is the surprise?
Here's another way of saying the same thing. After the button is pressed, what do you expect the program to do? Presently it does nothing but drop into the if_press routine if the button is in the target state. If the button is NOT in the target state, it STILL drops into the if_press routine. See the problem now?
If you were expecting the BUTTON command to WAIT for something, it doesn't. If you want it to re-execute if the button is not pressed, you must tell it to do so with program loop logic.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Main:
SERIN 16, 84,5000, Timeout, [noparse][[/noparse]DEC a] ' Await serial data
WRITE 1,a
READ 1,b
DEBUG ?b
DEBUG "2"
PAUSE 50
BUTTON Btn, 0, 200, 20, btnWrk, 0, if_press
GOTO main
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Are you now going to the timeout routine? If so, that's probably the problem.
It's quite difficult to work with only PARTS of programs. We need to see the ENTIRE program exactly as it was loaded into the Stamp to be able to offer any reliable assistance, otherwise, it's just guess work on our part.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->