poelstra / arduino-multi-button

Reliable detection of single, double and long clicks for Arduino.
MIT License
74 stars 15 forks source link

Ability to process a key matrix #7

Closed craiglindley closed 2 years ago

craiglindley commented 2 years ago

I have used you library for many projects and I thank you for it. It has worked great. I now have the need to interface with a 4x4 keyboard matrix where I would like to detect single, double and long presses on each of the 16 keys. Can your library be modified to do this?

poelstra commented 2 years ago

Sure! You have (at least) two options:

  1. Create a custom class MatrixButton, which derives from MultiButton. Check the existing PinButton class for how that would look. This class can then do the actual reading of your matrix button (e.g. toggling the column/row input/output pins). You would then create 16 instances of that MatrixButton class, like new MatrixButton(0, 0), MatrixButton(0, 1); etc...
  2. Just use 16 instances of MultiButton directly, and call its update() method with the 'raw' value of each button's pressed state.

The first one is probably the cleanest.

craiglindley commented 2 years ago

Thanks, I got my 4x4 matrix working great with your code. I used option 1. I put callbacks in each MultiButton for single, double and long clicks so they get called when any of the buttons are clicked. This will work great for my project.

Thanks for the great library

On Thu, Nov 18, 2021 at 2:22 PM Martin Poelstra @.***> wrote:

Sure! You have (at least) two options:

  1. Create a custom class MatrixButton, which derives from MultiButton. Check the existing PinButton class for how that would look. This class can then do the actual reading of your matrix button (e.g. toggling the column/row input/output pins). You would then create 16 instances of that MatrixButton class, like new MatrixButton(0, 0), MatrixButton(0, 1); etc...
  2. Just use 16 instances of MultiButton directly, and call its update() method with the 'raw' value of each button's pressed state.

The first one is probably the cleanest.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/poelstra/arduino-multi-button/issues/7#issuecomment-973282297, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6K5DYW5PPJQDGQWFZLY5DUMVVDFANCNFSM5IHXGJNA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Craig Lindley / Heather Hubbard

New Recordings are here http://craigandheather.net/spellbound.html

Personal Website is here http://craigandheather.net

Please call the Rockrimmon house. Our cell phones don't work at home. Rockrimmon House: (719) 426-9873 Craig's Cell: (719) 502-7925 Heather's Cell: (719) 571-0944

If you’re one in a million, there are now more than seven thousand people exactly like you.

poelstra commented 2 years ago

Cool! Glad you like it :)