three functions (press, double-click, long press) in one button


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: three functions (press, double-click, long press) in one button

    I use 3 function, 1 button:
    >short press, on/off
    >press 2 sec next function ( 8 hr on for example)
    >press/hold 5 sec to go to program function

    Led indicates mode,

    prioritize functions so you wait for less used functions

    this project was a lighting timer switch, press on/off, hold 2 sec for 8hr on, press to program(led blinks fast) set for 15,30,60 minutes stored to eeprom.
    fun project

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: three functions (press, double-click, long press) in one button

    Thanks,
    it seems to be impossible to fight against time, waiting for the other click in double-click.
    If you have many buttons then of course one could use a "boolean" variable for ex. enableDblClick and have it TRUE when you need double-cliks and FALSE when not and exit straight after long or short press. Then of course one should consider if there really is a need for all three functions for one button in the case if there are several buttons in you application. And as suggested, using short, semi-long and long press gives also 3 functions for one button...
    Many things are possible, but not exactly all

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: three functions (press, double-click, long press) in one button

    You could do something like:
    create 2 flags
    create 4 counters
    Set up a TMR interrupt to interrupt every 10 ms or so. Poll your button.
    If the button is down, increment two counters - "down1counter" and a "totaltimecounter" and set flag1. If flag1 is set and flag2 is not set, and the button is up, increment an "upcounter" and the totaltimecounter. Set flag 2. If flag 1 is set and flag 2 is set, and the button is down, increment down2counter and the totaltimecounter. Let totaltimecounter continue to run. After totaltimecounter has reached some value (a couple of seconds maybe), clear all counters to get ready for the next push(es).

    Before being cleared, the counters should have the information your program needs to make a decision. All in the background.
    Charles Linquist

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