Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Tuesday, October 13, 2009

4-Way Button: Click, Double-Click, Hold, Long Hold


How many ways can a button be clicked? [Anonymous] commented asking about double-clicking after my "Click for A, Press and Hold for B" post, and I finally got around to it, adding a long hold function too. Last night I tidied up the code and debugged obscure outlier cases, and the result is a simple 4-way button function which can report click, double-click, hold, and long hold events.

When used with a rotary input (pot, rotary encoder, jog-shuttle, etc), complex branching menus are easy to implement. Note that the long hold event always triggers a "normal" hold event first, while single- and double-click are completely independent (as well as being independent from the hold events).

I've posted code in the first two comments-- the tabs of my test sketch, with the second comment containing the checkButton() function. This seems like a good candidate for my first proper library; I would appreciate any help in getting this example sketch converted into an easily instantiated object, like AlphaBeta's Button library.

Thursday, May 14, 2009

Click for A, Press and Hold for B

I planned to add a time setting mode to the alarm clock later, as gravy-- thought I wouldn't need one since the clock chip keeps time-- but with the board not yet built, I keep accidentally disconnecting the DS1307's battery and needing to reset it with a special sketch.

That's a pain, so I'm adding it to the PPAC program next, and to keep the interface simple-- jog/shuttle and a button-- a press and hold event seems appropriate for switching into an otherwise hidden mode, like shutting down a MacBook by holding down the button instead of just clicking it.

Despite a few posted examples on debouncing a button press (explicitly or with a library), I couldn't find any press+hold examples, so I took a stab at it and got a test sketch working pretty quickly with a button and two indicator LEDs. The code is posted below, as a comment.