Re: [PIC}Discriminating between button presses
David C Brown <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.pic |
|---|---|
| Message-ID | <CAFo_nNq9r6rTGJL++Q16EjuLcFD_iHucd-Sdp7A-gx0T0DFyJg@mail.gmail.com> |
That is almost exactly the algorithm that I have come up with, with the addition that if there is no release after three seconds a long press is recorded I find it unsatisfactory because the action occurs when the button is released which is counterintuitive. Users expect pressing, not releasing, a button to do something. You have now set me the challenge of doing double clicks. After a short click wait half a second to see if there is another press? __________________________________________ David C Brown 43 Bings Road Whaley Bridge High Peak Phone: 01663 733236 Derbyshire eMail: [email protected] SK23 7ND web: www.bings-knowle.co.uk/dcb <http://www.jb.man.ac.uk/~dcb> *Sent from my etch-a-sketch* On Sat, 28 Dec 2024 at 18:08, Neil <[email protected]> wrote: > I did this for a product several years ago using 8-bit PICs and can > distinguish between short presses, long presses, and double-clicks (<-- > this was most challenging). It also included debouncing. Worked very > well over several thousands of units. > > I thought of it "graphically": an interrupt about 10 times/sec would > left shift a register and capture the button state into the LSB. So the > bits of that register really looked like a logic analyzer trace. > On each interrupt I'd look for a pattern using a mask... if the button > was 0 on press, I would look for 0x___11110 which means that the button > was just pressed. If there was bounce, then the 1111 part would include > 0's, would would only register the press after the bounces stabilized. > The amount of 1's depends on how bouncy the button is, but less if more > responsive. > > When the press occurs I start counting time... actually just reset a > counter that another timer interrupt was counting. > The prior interrupt also looked for release ( 0x_____01). The amount of > time it took to get the release determined if it was a short vs long > press. Set flag for short and long-presses accordingly to let main code > process it. > > FWIW, a short press just set a flag and another time-counter and if > second short-press was received within a specific time, then that was a > double-click, else the time-counter generated the click event and flags. > There was some tricky code to do this part, so I can't remember the > low-level details on it currently. > > Cheers, > -Neil. > > > > On 12/28/2024 12:15 PM, David C Brown wrote: > > Using mid range 16bit PICs I am attempting to write an algorithm that can > > discriminate between short - less than 1 second - and long - greater > than 3 > > second - button presses. > > I have written some thing which works but I am not entirely satisfied > with > > it and would appreciate and guidance/suggestion > > __________________________________________ > > David C Brown > > 43 Bings Road > > Whaley Bridge > > High Peak Phone: 01663 733236 > > Derbyshire eMail: [email protected] > > SK23 7ND web: www.bings-knowle.co.uk/dcb > > <http://www.jb.man.ac.uk/~dcb> > > > > > > > > *Sent from my etch-a-sketch* > > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > https://mailman.mit.edu/mailman/listinfo/piclist >