#include <I2CKeyPad.h>
#define deltaTime(val) (millis()-val)
I2CKeyPad keyPad(0x38);
char keypad_layout[19] = "123A456B789C*0#DNF"; // N = NO_KEY, F = FAILED
// Just to avoid spamming
unsigned long lastKeyPress = 0;
unsigned long keyDelay = 200;
void setup() {
Serial.begin(9600);
if (!keyPad.begin()) {
Serial.print("Cannot connect to I2C.\n");
while(1);
}
keyPad.loadKeyMap(keypad_layout);
}
void loop() {
if (keyPad.isPressed() && deltaTime(lastKeyPress) > keyDelay) {
lastKeyPress = millis();
char ch = keyPad.getChar();
Serial.println("Pressed : " + String(ch));
}
// Makes the code run faster
delay(10);
}