Shop OBEX P1 Docs P2 Docs Learn Events
waiting for user input (button) to start — Parallax Forums

waiting for user input (button) to start

NeohavenNeohaven Posts: 13
edited 2005-07-10 04:12 in BASIC Stamp
what would a code to do this would be? i have alerady done a serial communication input wait, but i just seem to get stuck when im with input pins and all...

any help would be appreciated, thanks!

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-08 21:57
    Hello,

    ·· You could try:

    DO : LOOP UNTIL IN0 = 0
    

    This would wait until an active LOW button on P0 was pressed to continue.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-08 22:04
    I was going to provide the same snippet. Neohaven, one thing to watch out for, is that this code snippet does not debounce the button. If you are only checking the button once before entering into the remainder of your code, this shouldn't be an issue. But if you check the button, execute a couple lines of code, then start looking at the button status again, you'll have to take this into account.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Vern GranerVern Graner Posts: 337
    edited 2005-07-08 23:10
    Here's what I use for most of my code:

    For BS1:

    SYMBOL  BUT1      = 1 ' N.O. Momentary Push Button on PIN1
    SYMBOL  btnWrk   = B2 ' Workspace for BUTTON
    
    Main:
      BUTTON BUT1, 1, 200, 20, btnWrk, 0, MAIN
    
    



    For BS2:

    BUT1    CON 1    ' N.O. Momentary Push Button on PIN1
    btnWrk VAR Byte  ' Workspace for BUTTON               
    
    waitbut1:
      BUTTON BUT1, 1, 255, 250, btnWrk, 0, waitbut1
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Vern Graner CNE/CNA/SSE    | "If the network is down, then you're
    Senior Systems Engineer    | obviously incompetent so why are we
    Texas Information Services | paying you? Of course,if the network
    http://www.txis.com        | is up, then we obviously don't need
    Austin Office 512 328-8947 | you, so why are we paying you?" ©VLG
    
    
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-07-08 23:57
    Yeah, that's why BUTTON for the BS2 is so nice, debounces for you ~

    Ryan
  • NeohavenNeohaven Posts: 13
    edited 2005-07-09 00:01
    ok.... what's debouncing?!

    sry im a total noob (in ucontrol, that is...)
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-07-09 03:44
    When you push a 'mechanical' switch, there is (however small) an amount of 'bouncing' - (See Newton's Laws [noparse];)[/noparse]

    For example, when you click a switch there is 'noise' in the signal, which is a result of the physical 'bouncing' (for lack of a better word)- Keys on a keyboard need to be debounced as well....think of slamming a basketball down to the ground as hard as you can...there is, however small, an amount of bouncing...on smaller things like buttons and switches you (a human) can't see this, but electronics, much more sensitive and fast, do see these effects...

    http://whatis.techtarget.com/definition/0,,sid9_gci214068,00.html

    To debounce something means to make multiple 'spikes' be seen as a single edge event-

    Ryan
  • NeohavenNeohaven Posts: 13
    edited 2005-07-09 04:52
    like filtering the signal?
  • ERMERM Posts: 34
    edited 2005-07-10 04:12
    Try this little experiment and you will understand what debounce is.

    With your index finger, the one next to your thumb [noparse]:)[/noparse] , press it to the side of your head at a slight angle just above your ear. Assuming you have hair, you will hear a crackling sound. When a switch is pressed, electronics hear the same thing in the switch but think it's the switch being pressed multiple times. The debounce tells the processor all that crackling is one press just like your brain tells you it's one finger pressing one time.

    That should help clarify things a bit.
Sign In or Register to comment.