1 switch, 1 pin, "single click, double click..."


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Posts
    74

    Default 1 switch, 1 pin, "single click, double click..."

    I have a PIC12F683
    - 1 pin as an input.
    - Using a momentary button

    I want to be able to push the button once "single click" and have it execute one thing, and also have it if the button is pressed in quick succession "double click" it executes another thing.

    I have looked at
    -PULSIN - short click vs. long click
    -RCTIME - same, short vs long
    -COUNT - single versus double click
    -IF..THEN - short vs long click

    I want the most efficient way to get it done.

    thanks
    -eric

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by erice1984 View Post
    I have a PIC12F683
    - 1 pin as an input.
    - Using a momentary button

    I want to be able to push the button once "single click" and have it execute one thing, and also have it if the button is pressed in quick succession "double click" it executes another thing.

    I have looked at
    -PULSIN - short click vs. long click
    -RCTIME - same, short vs long
    -COUNT - single versus double click
    -IF..THEN - short vs long click

    I want the most efficient way to get it done.

    thanks
    -eric
    You might try the Count command, store the count in a variable and compare the variable to what you want to do. You might get some problems from switch bounce that way though.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jul 2007
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    MAIN:
    low ind
    if but = 0 then
    pause 8
    count but,500,b0
    pause 5
    goto bpres
    else
    goto main
    endif

    Yeah, I had ran through everything, count seems to be the easiest way to go, I added a small pause in there between BUT=0 and COUNT to wait for some bounce to settle. Only other option was looking to aid in the external debounce circuit area. It upped the consistency but sometimes my LED doesnt light when I hit the button, though I think it may be my button since it has a lot of travel.
    Last edited by erice1984; - 27th March 2009 at 22:33.

  4. #4
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Post

    I would do it by defining a time window for input signal. After button is pressed you will wait certain time (loop) and if button is re-pressed during that time then excecute "button twice pressed" -task. If time runs out then "button once pressed" -task.

    IF -THEN could be used, also to get debounce delay.

    Also if button is held down then do check for that too and continue only after button is released. Then you can support both short and long clicks.

    BR,
    -Gusse-
    Last edited by Gusse; - 27th March 2009 at 22:54.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Probably thousand different ways to do it, but here's one top of my head.

    Detect the first push button press, from there, start a timer, if you get another push-button press before the timer overflow, you have your double-click condition satisfied.
    same thing as Gusse i guess... DOH!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi, Steve

    Might work with two " Button" commands following each other, as debounce time is effective ONLY if condition TRUE ...

    he,he ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Maybe... but as you know, I never use Button, so...

    Someone could also go crazy and use CLKI + timer interrupt.... this allow 1,2,3,4,5... click triggers for a x period of time, with a real minimum of code line, something <10 code line I guess.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Dec 2007
    Location
    Finland
    Posts
    191


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by Acetronics View Post
    Hi, Steve

    Might work with two " Button" commands following each other, as debounce time is effective ONLY if condition TRUE ...

    he,he ...

    Alain
    I haven't use Button -command too, but couple of IF - THEN with PAUSE works for me.
    Code:
    IF But = 0 then         'Button is pressed and debounce detections starts 
        PAUSE 100           'wait 100ms or some other more suitable time
        IF But = 0 then     'if button is still held down then do something
                            'start timer or loop for 2nd button press detection ...
    I think, some time window must be defined otherwise you will be waiting that other press forever...

    Also nice to hear that Steve had similar thoughts

    BR,
    -Gusse-
    Last edited by Gusse; - 28th March 2009 at 10:04.

Similar Threads

  1. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 13:35
  2. Optimizing DIV
    By skimask in forum mel PIC BASIC Pro
    Replies: 41
    Last Post: - 22nd September 2008, 04:58
  3. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26
  4. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  5. DS1820 headache
    By Calco in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 12th August 2004, 00:28

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts