Shop OBEX P1 Docs P2 Docs Learn Events
Button woes — Parallax Forums

Button woes

ArchiverArchiver Posts: 46,084
edited 2001-04-12 06:13 in General Discussion
Here's the problem:

I need one button to select a function and then, after the selection
is made, the program branches where it needs to go.

I have nested the button command in a for next loop. I have tried it
without using the button command, by looking at the state of the
input (switch) pin.

Problem is: The branching occurs to quickly.

I would like the branching to occur upon release of the button, not
before. As the loop increments (x=1, x=2, x=3...) the program
branches each time x is incremented. Not what I what I want. I want
to escape the loop and branch after release of the pusbutton.

Two questions remain:

1) Did I make any sense
2) If so, how is it done.

Thanks

Rich

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-04-11 23:17
    I'm no expert but try this.
    top:

    for var=1 to ?
    if in1=1 then top
    pause 10
    next var
    wait:
    if in1=0 then wait
    goto ?????
    hope this helps
    regards victor
    Original Message
    From: <rbc1956@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Wednesday, April 11, 2001 4:14 PM
    Subject: [noparse][[/noparse]basicstamps] Button woes


    > Here's the problem:
    >
    > I need one button to select a function and then, after the selection
    > is made, the program branches where it needs to go.
    >
    > I have nested the button command in a for next loop. I have tried it
    > without using the button command, by looking at the state of the
    > input (switch) pin.
    >
    > Problem is: The branching occurs to quickly.
    >
    > I would like the branching to occur upon release of the button, not
    > before. As the loop increments (x=1, x=2, x=3...) the program
    > branches each time x is incremented. Not what I what I want. I want
    > to escape the loop and branch after release of the pusbutton.
    >
    > Two questions remain:
    >
    > 1) Did I make any sense
    > 2) If so, how is it done.
    >
    > Thanks
    >
    > Rich
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-12 00:11
    >Here's the problem:
    >
    >I need one button to select a function and then, after the selection
    >is made, the program branches where it needs to go.
    >
    >I have nested the button command in a for next loop. I have tried it
    >without using the button command, by looking at the state of the
    >input (switch) pin.
    >
    >Problem is: The branching occurs to quickly.
    >
    >I would like the branching to occur upon release of the button, not
    >before. As the loop increments (x=1, x=2, x=3...) the program
    >branches each time x is incremented. Not what I what I want. I want
    >to escape the loop and branch after release of the pusbutton.
    >
    >Two questions remain:
    >
    >1) Did I make any sense
    >2) If so, how is it done.
    >

    Here is one way, programmatic:

    but var in0 ' button on p0, active low.
    waiting1:
    if but=0 then waiting1 ' wait for button to be up
    waiting0:
    if but=1 then waiting0 ' wait for button to be down
    do_it:
    'this happens when button goes down.
    goto waiting1


    Here is another way, state machine:

    new var bit ' new state of button
    old var bit ' old state of button
    ' button on p0.. active low

    old=1 ' inactive to start
    waiting:
    new=in0 ' logic detects 1->0 transition
    if old ^ new & old then do_it
    'rest of stuff in waiting loop
    goto waiting:

    do_it:
    old=new ' update state
    ' rest of stuff to do
    goto waiting

    The formula, )old ^ new & old), uses the XOR operator between the old
    and the new state to detect a transition, and then ANDs that with
    the old state to narrow it down to the 1-->0 transition. The
    programmatic approach is easier to understand and implement
    initially, but the state machine approach lends itself more readily
    to further development with more inputs and actions.

    I hope that helps,

    -- regards,
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-12 00:32
    Oops, I put the old=new in the wrong place in the "state" program, so
    as it would never detect the return to pushbutton up. Here is a
    correction...

    new var bit ' new state of button
    old var bit ' old state of button
    ' button on p0.. active low

    new=in0 ' starting state
    waiting:
    old=new
    new=in0 ' logic detects 1->0 transition
    if old ^ new & old then do_it
    'rest of stuff in waiting loop
    goto waiting:

    do_it:
    ' stuff to do
    goto waiting

    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2001-04-12 06:13
    You need to use a for / nect loop to determine when the button has bee
    npressed, and when pressed, send the program to another for/next loop that
    determines when the button is released, once released, run the code
    required.
    Chris
    Original Message
    From: <rbc1956@y...>
    To: <basicstamps@yahoogroups.com>
    Sent: Thursday, April 12, 2001 4:14 AM
    Subject: [noparse][[/noparse]basicstamps] Button woes


    > Here's the problem:
    >
    > I need one button to select a function and then, after the selection
    > is made, the program branches where it needs to go.
    >
    > I have nested the button command in a for next loop. I have tried it
    > without using the button command, by looking at the state of the
    > input (switch) pin.
    >
    > Problem is: The branching occurs to quickly.
    >
    > I would like the branching to occur upon release of the button, not
    > before. As the loop increments (x=1, x=2, x=3...) the program
    > branches each time x is incremented. Not what I what I want. I want
    > to escape the loop and branch after release of the pusbutton.
    >
    > Two questions remain:
    >
    > 1) Did I make any sense
    > 2) If so, how is it done.
    >
    > Thanks
    >
    > Rich
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
Sign In or Register to comment.