Shop OBEX P1 Docs P2 Docs Learn Events
BUTTON command — Parallax Forums

BUTTON command

philipad23philipad23 Posts: 44
edited 2006-02-12 07:34 in BASIC Stamp
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?

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-12 04:56
    Philip -

    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 WilliamsJon Williams Posts: 6,491
    edited 2006-02-12 04:57
    When you add a timeout value to SERIN you must also specify a location to jump to when the timeout occurs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • philipad23philipad23 Posts: 44
    edited 2006-02-12 05:33
    Thanks for the replies.... But still dont get it...
    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?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-12 05:46
    You have --


    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.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-12 05:54
    Philip -

    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 -->
  • philipad23philipad23 Posts: 44
    edited 2006-02-12 06:10
    I agree with that Bruce but I tried to put GOTO main and still dont get it... I think it should and continue getting the data from the serial...

    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 WilliamsJon Williams Posts: 6,491
    edited 2006-02-12 07:24
    What are you trying to accomplish? There may be another way that is more effective.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-12 07:34
    Philip -

    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 -->
Sign In or Register to comment.