2021-11-08 07:13:29 -05:00
|
|
|
//
|
|
|
|
// FILE: I2Ckeypad_keymap.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: demo key mapping
|
|
|
|
// URL: https://github.com/RobTillaart/I2CKeyPad
|
2021-12-19 14:23:20 -05:00
|
|
|
//
|
2021-11-08 07:13:29 -05:00
|
|
|
// PCF8574
|
|
|
|
// pin p0-p3 rows
|
|
|
|
// pin p4-p7 columns
|
|
|
|
// 4x4 or smaller keypad.
|
|
|
|
|
|
|
|
|
|
|
|
#include "Wire.h"
|
|
|
|
#include "I2CKeyPad.h"
|
|
|
|
|
|
|
|
const uint8_t KEYPAD_ADDRESS = 0x38;
|
|
|
|
|
|
|
|
I2CKeyPad keyPad(KEYPAD_ADDRESS);
|
|
|
|
|
|
|
|
char keymap[19] = "123A456B789C*0#DNF"; // N = NoKey, F = Fail
|
|
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
|
|
|
|
Wire.begin();
|
|
|
|
Wire.setClock(400000);
|
|
|
|
if (keyPad.begin() == false)
|
|
|
|
{
|
|
|
|
Serial.println("\nERROR: cannot communicate to keypad.\nPlease reboot.\n");
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
keyPad.loadKeyMap(keymap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
if (keyPad.isPressed())
|
|
|
|
{
|
|
|
|
char ch = keyPad.getChar(); // note we want the translated char
|
|
|
|
int key = keyPad.getLastKey();
|
|
|
|
Serial.print(key);
|
|
|
|
Serial.print(" \t");
|
|
|
|
Serial.println(ch);
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|
2021-12-19 14:23:20 -05:00
|
|
|
|