GY-63_MS5611/libraries/I2CKeyPad/examples/I2Ckeypad_demo02/I2Ckeypad_demo02.ino

73 lines
1.4 KiB
Arduino
Raw Normal View History

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