A new way to connect buttons and save pins

This example has 16 buttons connected to a Nano and saves 7 pins.

  • No external port expander(s) required.
  • Supports multiple press (by row) and provides built-in debounce.

Code and simulation

Any suggestions / comments welcome!

That sounds good, but as i see it just well known "keyboard matrix"...

Just organized that way, but the buttons are independant. Uses pwm to provide the "released" state and also provide built-in debounce. The buttons aren't connected in matrix format. No ghosting issues and allows up to 8 buttons pressed simultaneously (by row).

Could you possibly explain how this works?

Each input has several buttons connected like this ... (revised: see post #8)

Err....
And when you press both buttons at the same time?

:sparkler:

3 Likes

This is also the case for matrices right? Problems arise when buttons on different rows and columns are pressed and a third button is pressed on one of the intersections.

Just the addition of one 330Ω resistor would protect all buttons (and your power source)!

image

Multiple simultaneous presses are done by row, not by column. Any feature requiring multiple buttons press should have them connected in a row (using separate inputs).

True, but this method allows more buttons to be pressed simultaneously without interference. Pressing any 2 buttons "vertically" will give invalid results.

In the simulation example, you can use PC's keyboard to press up to 3 buttons simultaneously (i.e. abc), then use the mouse to press a fourth button.

Sure, but this also holds for matrices.

What happens when button A, B and J are pushed? Do you see ghosting on button I?

Intriguing idea by the way.

No ghosting, no diodes, just pwm and logic detection.

Here's the signal on pin 4 with lower button pressed first, then upper button pressed. You can see the bounce on the signal (thicker line) - this is debounced by the code and the pwm sample period.

Are you sure?

When I try the simulation and push button A, i see:

1	0

Then when I additionally push button J, I see:

1	10

But when I then push button B, I see two lines:

11	10
11	0

instead of the expected

10	0

Am I misinterpreting the serial output perhaps?

A and J are on different rows, so results are invalid. you can press abc..., or ijk... or any combination (by row) or independently.

Additional info:
Button released state gives a pwm signal on the input. This is detected in the code by checking for 0x55 or 0xAA on the status variable.

I love projects like this. This kind of exploration is important to innovation.
As of yet though I do not see the advantage of this over a key matrix.

The key matrix uses less pins by 1, does not require a timer, and can be made without taking a PWM pin. It can also be debounced cheaply in software.

I like to use an 8051 or a tiny88 to offload keypads, they can be configured as 1 wire, I2C, or SPI as determined by the rest of the project.

Is there an advantage here that I'm missing?

This is meant for all the various discrete buttons and switches used in projects where a keypad isn't suitable. Perhaps toggle switches and buttons are placed in various locations or spread over a larger area. Boats, automotive, robotics, etc.

Oh, worth mentioning ... no debounce library or code needed. Uses this debounce algorithm internally.

1 Like

This will work with the widgets spread out?
A standard matrix won't?
Genuinely curious.

Yes, spread out in pairs.

And a standard matrix will fail in that situation?

A standard keypad matrix groups your buttons in one small location. Sometimes you may have larger switches and buttons that need to be separate and meet different ergonomic requirements.