Jittery buttons - does Keypad lib's debounce work?

I have a 4x4 button pad and am using the Keypad library to read it.

I’m (trying to) use the Keypad library’s built in debounce and have tried various debounce times from 1ms all the way up to 200ms but no matter where I set it, the buttons are very jittery - that is - when I tap a button (rubber button pad pushing down on PCB), sometimes it goes on/off, or on/off/on, etc…

So I’m wondering, does the Keypad lib’s built in debouncing actually work? does it only work if I use the event handler method?

Here is my code (left off all cases past 1 as they’re exactly the same except for different positions on the grid of course)


--r1  0,4 0,5 0,6 0,7
--r2  1,4 1,5 1,6 1,7
--r3  2,4 2,5 2,6 2,7
--r4  3,4,3,5 3,6 3,7

      c1  c2  c3  c4
      |    |  |    |


#include <Sprite.h>  // Sprite before Matrix
#include <Matrix.h>

#include <Keypad.h>

// LED Matrix
const int numChips = 1;

//                   DIN, CLK, LOAD, #chips
Matrix myLeds = Matrix(19, 18, 17, numChips);

int ledState[16] = 

//Keypad Matrix
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] =
  {'1', '2', '3', '4'},
  {'5', '6', '7', '8'},
  {'9', 'a', 'b', 'c'},
  {'d', 'e', 'f', 'g'}

byte colPins[COLS] = {45, 41, 37, 33};

byte rowPins[ROWS] = {31, 35, 39, 43};

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int i = 0;

// Setup / init functions

void setup() 

void loop() 

  char key = kpd.getKey();

  if (key != NO_KEY && kpd.getState() == PRESSED)
      case '1':
        if(ledState[0] == LOW)
          ledState[0] = HIGH;
          //Serial.print("0,4 HIGH");
          ledState[0] = LOW;
         // Serial.print("0,4 LOW");
      case '2':

etc, etc, etc

Any & all help appreciated… I have finally got the damn LED driver working… the only thing holding me back from programming now is the jittery buttons.

try commenting out these 2 lines, see if that helps.

kpd.setDebounceTime(20); kpd.setHoldTime(0);

The first sets the time between the library recognizing key presses, if you wanted to sit there & really hammer it. 20mS is 50 key presses a second. Not sure key is even done bouncing that quick. The second sets the time until the library treats the key as being pressed & held.

I have a velleman 4x4 keypad and the library worked great with none of the other stuff set.

Wow, it was that simple!


That is really weird, but.. I wont be complaining hehe