Shop OBEX P1 Docs P2 Docs Learn Events
Button Delay, Reset type functionality — Parallax Forums

Button Delay, Reset type functionality

DShannonDShannon Posts: 26
edited 2005-03-04 13:52 in BASIC Stamp
Hi all,
A question that i'm sure someone can help with.

With 1 button input to the stamp, I need to perform 2 functions, based on the following rule:

1) If button is held down for 3 seconds, function "X" is performed
2) else, function "Y" is performed if button is pushed for only 100 ms

This would be like a digital clock in a car - If I hold down the button, I enter clock setting mode. however, If i momentarily press the same button, the clock changes modes (ie, shows the calendar date)

I have racked my brain and tried different IF THEN logic, but cant seem to get it, even a "hack"!

Any ideas????

Thanks!
-Dan

Comments

  • DShannonDShannon Posts: 26
    edited 2005-03-04 01:54
    Also, funtion "Y" should be performed immediately.....
  • TimTechTimTech Posts: 3
    edited 2005-03-04 03:01
    It would be something like this in psudocode:

    1) Wait until button is pressed
    2) Set a variable to 0 ("Timer" for example)
    3) Wait until button is released, incrementing Timer each time through
    4) If Timer > 3 seconds Then "X"
    5) Else if Timer < 100ms Then "Y"
    6) GOTO 1)

    Post Edited (TimTech) : 3/4/2005 3:03:32 AM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-03-04 03:11
    There is quite a bit of this kind of coding in the first couple of chapters of the "Applied Sensors" text available for free download at the Parallax web site.

    Something like this:
    ticks VAR Byte

    top:
    DO
      ' put other program stuff here
    LOOP UNTIL in0=0   ' until the button input is pressed
    
    DO
      ticks=ticks+1
      IF ticks>60 THEN setClock  ' jump after 3 seconds
      pause 50    ' units of 50millisecs
    LOOP UNTIL in0=1   ' until the button is released
    
    SELECT ticks
    CASE <  3   ' less than 150 ms
      GOTO changeMode
    CASE > 3   ' what happens if it is between 0.15 and 3 seconds?
       GOTO whatever
    ENDSELECT
    
    setClock:
      ' do it
      DO : LOOP UNTIL in0=1  ' to wait for user to release button
      GOTO top
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • DShannonDShannon Posts: 26
    edited 2005-03-04 13:52
    AAhhhhh! yes. this makes sense. Thanks for your help! I will give it a go........
Sign In or Register to comment.