65 lines
1.1 KiB
Arduino
Raw Normal View History

2021-01-29 12:31:58 +01:00
//
// FILE: I2Ckeypad_demo01.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/I2CKeyPad
//
2021-11-08 13:13:29 +01:00
// PCF8574
2021-01-29 12:31:58 +01:00
// pin p0-p3 rows
2021-11-08 13:13:29 +01:00
// pin p4-p7 columns
// 4x4 or smaller keypad.
2021-01-29 12:31:58 +01:00
2021-05-08 09:52:18 +02:00
2021-01-29 12:31:58 +01:00
#include "Wire.h"
#include "I2CKeyPad.h"
const uint8_t KEYPAD_ADDRESS = 0x38;
2021-05-08 09:52:18 +02:00
I2CKeyPad keyPad(KEYPAD_ADDRESS);
2021-01-29 12:31:58 +01:00
uint32_t start, stop;
uint32_t lastKeyPressed = 0;
2021-05-08 09:52:18 +02:00
2021-01-29 12:31:58 +01:00
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Wire.begin();
Wire.setClock(400000);
2021-05-08 09:52:18 +02:00
if (keyPad.begin() == false)
2021-01-29 12:31:58 +01:00
{
Serial.println("\nERROR: cannot communicate to keypad.\nPlease reboot.\n");
while(1);
}
}
void loop()
{
uint32_t now = millis();
2021-11-08 13:13:29 +01:00
char keys[] = "123A456B789C*0#DNF"; // N = NoKey, F = Fail
2021-01-29 12:31:58 +01:00
if (now - lastKeyPressed >= 100)
{
lastKeyPressed = now;
start = micros();
2021-11-08 13:13:29 +01:00
uint8_t index = keyPad.getKey();
2021-01-29 12:31:58 +01:00
stop = micros();
Serial.print(millis());
Serial.print("\t");
2021-11-08 13:13:29 +01:00
Serial.print(index);
2021-01-29 12:31:58 +01:00
Serial.print("\t");
2021-11-08 13:13:29 +01:00
Serial.print(keys[index]);
2021-01-29 12:31:58 +01:00
Serial.print("\t");
Serial.println(stop - start);
}
}
2021-11-08 13:13:29 +01:00
2021-01-29 12:31:58 +01:00
// -- END OF FILE --
2021-11-08 13:13:29 +01:00