2021-01-29 06:31:58 -05:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: I2CKeyPad.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2024-07-18 11:15:18 -04:00
|
|
|
// VERSION: 0.5.0
|
2021-11-08 07:13:29 -05:00
|
|
|
// PURPOSE: Arduino library for 4x4 KeyPad connected to an I2C PCF8574
|
2021-01-29 06:31:58 -05:00
|
|
|
// URL: https://github.com/RobTillaart/I2CKeyPad
|
|
|
|
|
2021-11-08 07:13:29 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Wire.h"
|
|
|
|
|
2021-11-08 07:13:29 -05:00
|
|
|
|
2024-07-18 11:15:18 -04:00
|
|
|
#define I2C_KEYPAD_LIB_VERSION (F("0.5.0"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
#define I2C_KEYPAD_NOKEY 16
|
|
|
|
#define I2C_KEYPAD_FAIL 17
|
2024-07-18 11:15:18 -04:00
|
|
|
//
|
|
|
|
#define I2C_KEYPAD_THRESHOLD 255
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-09-29 10:17:30 -04:00
|
|
|
// experimental
|
|
|
|
#define I2C_KEYPAD_4x4 44
|
|
|
|
#define I2C_KEYPAD_5x3 53
|
|
|
|
#define I2C_KEYPAD_6x2 62
|
|
|
|
#define I2C_KEYPAD_8x1 81
|
|
|
|
|
2021-11-08 07:13:29 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
class I2CKeyPad
|
|
|
|
{
|
|
|
|
public:
|
2021-05-08 03:52:18 -04:00
|
|
|
I2CKeyPad(const uint8_t deviceAddress, TwoWire *wire = &Wire);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2023-11-11 11:08:08 -05:00
|
|
|
// call Wire.begin() first!
|
2024-07-18 11:15:18 -04:00
|
|
|
bool begin();
|
|
|
|
bool isConnected();
|
2021-11-08 07:13:29 -05:00
|
|
|
|
2021-12-19 14:23:20 -05:00
|
|
|
// get raw key's 0..15
|
2024-07-18 11:15:18 -04:00
|
|
|
uint8_t getKey();
|
|
|
|
uint8_t getLastKey();
|
|
|
|
bool isPressed();
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2021-12-19 14:23:20 -05:00
|
|
|
// get 'translated' keys
|
2022-09-29 10:17:30 -04:00
|
|
|
// user must load KeyMap, there is no check.
|
2024-07-18 11:15:18 -04:00
|
|
|
uint8_t getChar();
|
|
|
|
uint8_t getLastChar();
|
|
|
|
void loadKeyMap(char * keyMap); // char[19]
|
2022-09-29 10:17:30 -04:00
|
|
|
|
|
|
|
// mode functions - experimental
|
2024-07-18 11:15:18 -04:00
|
|
|
void setKeyPadMode(uint8_t mode = I2C_KEYPAD_4x4);
|
|
|
|
uint8_t getKeyPadMode();
|
|
|
|
|
|
|
|
// value in milliseconds, max 65535 ms
|
|
|
|
void setDebounceThreshold(uint16_t value = 0);
|
|
|
|
uint16_t getDebounceThreshold();
|
|
|
|
uint32_t getLastTimeRead();
|
2021-11-08 07:13:29 -05:00
|
|
|
|
2021-12-19 14:23:20 -05:00
|
|
|
|
2021-11-08 07:13:29 -05:00
|
|
|
protected:
|
2024-07-18 11:15:18 -04:00
|
|
|
uint8_t _address;
|
|
|
|
uint8_t _lastKey;
|
|
|
|
uint8_t _mode;
|
|
|
|
uint8_t _read(uint8_t mask);
|
|
|
|
uint16_t _debounceThreshold;
|
|
|
|
uint32_t _lastTimeRead;
|
|
|
|
|
|
|
|
uint8_t _getKey4x4();
|
|
|
|
uint8_t _getKey5x3();
|
|
|
|
uint8_t _getKey6x2();
|
|
|
|
uint8_t _getKey8x1();
|
2022-09-29 10:17:30 -04:00
|
|
|
|
2021-05-08 03:52:18 -04:00
|
|
|
TwoWire* _wire;
|
2022-09-29 10:17:30 -04:00
|
|
|
|
2021-11-08 07:13:29 -05:00
|
|
|
char * _keyMap = NULL;
|
2021-01-29 06:31:58 -05:00
|
|
|
};
|
|
|
|
|
2021-11-08 07:13:29 -05:00
|
|
|
|
2023-11-11 11:08:08 -05:00
|
|
|
// -- END OF FILE --
|
2021-11-08 07:13:29 -05:00
|
|
|
|