// flunk any autorepeated tokens by timewindow
// like debounce:
// react to first and ignore any until T after last. repeated token
// here with gotten characters from a keypad said to be bouncing (almost certainly not, but hey!)
# include <Keypad.h>
# define BOUNCE 777 // exaggerated for testing
const unsigned char ROWS = 4;
const unsigned char COLS = 3;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
//const unsigned char ROWS = sizeof ;
//const unsigned char COLS = 3;
unsigned char colPins[COLS] = {5, 4, 3};
unsigned char rowPins[ROWS] = {9, 8, 7, 6 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(115200);
Serial.println("\nReject Repeat Delta\n");
}
char lastKey = NO_KEY;
unsigned long lastTime;
void loop() {
unsigned long now = millis();
char key = keypad.getKey();
bool handled = false;; // unless proven otherwise
// nothing
if (key == NO_KEY) handled = true; // IR has no NO_KEY concept? check...
// this eats repeated too soon entries
if (key == lastKey) {
if (now - lastTime < BOUNCE) handled = true;
lastTime = now;
}
// here you have key the keystroke
if (!handled) {
lastKey = key;
lastTime = now;
Serial.println(key);
}
}