I have 8 sets of 8 push buttons. There is a Teensy and a demultiplexer. The demultiplexer has 8 outputs. When an output is selected it is pulled low. Each output is connected to a group of 8 push buttons. The 8 push buttons are then connected to 8 pullup inputs on the Teensy.

Each group of 8 push buttons is connected to a unique demultiplexer output, but all the push buttons are connected to the same 8 inputs on the Teensy. That is, push button #1 in group 1 shares a Teensy input with push button #1 in group 2. The push buttons are isolated from each other with diodes.

I'm using bounce.h for debouncing. It looks for rising and falling edges.

The problem is this:

  • Push button #1 in group #1 is pressed, pulling that input low, causing a falling edge to be detected. This is good.
  • The demultiplexer shifts to group #2, where the #1 button hasn't been pressed, and thus is high.
  • Because both #1 buttons in group #1 and #2 share the same input line, the Teensy sees this change as a rising edge. This is undesired.

What is the better approach to this?



  • Why is a rising edge undesired when the switch going low is what you are looking for? Who cares if it goes high?
    – Nick Gammon
    Sep 4, 2017 at 7:38
  • When you press a button there is an initial rising edge, and if you keep that button pressed until the demux cycles all the way around, it will detect another rising edge, and will keep doing this. It also detects a falling edge right as soon as the demux shifts away from the still-pressed button. These extra rising and falling edges don't accurately portray the state of the buttons, and so I'm trying to filter them out, or go about detecting the button states differently.
    – Daniel
    Sep 4, 2017 at 7:48
  • When you press a button there is an initial rising edge - When an output is selected it is pulled low - these statements contradict each other. When you press a button these is a falling edge.
    – Nick Gammon
    Sep 4, 2017 at 9:45
  • Yes I have those backwards.
    – Daniel
    Sep 7, 2017 at 4:19

2 Answers 2


To do multiplexing with bounce.h you will need one bounce object per button. That's 64 bounce objects for an 8x8 matrix.

Then you only want to update the bounce objects for the group you currently have active.

That is:

  1. Switch to group 1.
  2. Update objects 1-8
  3. Switch to group 2
  4. Update objects 9-16
  5. ... etc ...

You need one object per button so that the internal data can track the state of that specific button, and you only update the 8 objects for the currently selected group otherwise the objects that aren't associated with that group will get confused by incorrect data.


What is the better approach to this?

write your code so it debounces each pin / group of pins separately.

looks like your code used global / static variables.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.