0.2.0 I2CKeyPad8x8

This commit is contained in:
Rob Tillaart 2023-11-11 17:09:31 +01:00
parent 8cf136ecad
commit 82e0c516c3
8 changed files with 68 additions and 51 deletions

View File

@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.0] - 2023-11-09
- simplify begin()
- update readme.md
- minor edits.
## [0.1.1] - 2022-11-12 ## [0.1.1] - 2022-11-12
- Add RP2040 support to build-CI. - Add RP2040 support to build-CI.
- Add CHANGELOG.md - Add CHANGELOG.md

View File

@ -1,11 +1,9 @@
// //
// FILE: I2CKeyPad8x8.cpp // FILE: I2CKeyPad8x8.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1 // VERSION: 0.2.0
// PURPOSE: Arduino library for 8x8 or smaller KeyPad connected to an I2C PCF8575. // PURPOSE: Arduino library for 8x8 or smaller KeyPad connected to an I2C PCF8575.
// URL: https://github.com/RobTillaart/I2CKeyPad8x8 // URL: https://github.com/RobTillaart/I2CKeyPad8x8
//
// HISTORY: see changelog.md
#include "I2CKeyPad8x8.h" #include "I2CKeyPad8x8.h"
@ -19,23 +17,18 @@ I2CKeyPad8x8::I2CKeyPad8x8(const uint8_t deviceAddress, TwoWire *wire)
} }
#if defined(ESP8266) || defined(ESP32) bool I2CKeyPad8x8::begin()
bool I2CKeyPad8x8::begin(uint8_t sda, uint8_t scl)
{ {
_wire->begin(sda, scl);
// enable interrupts // enable interrupts
_read(0xFF00); _read(0xFF00);
return isConnected(); return isConnected();
} }
#endif
bool I2CKeyPad8x8::begin() bool I2CKeyPad8x8::isConnected()
{ {
_wire->begin(); _wire->beginTransmission(_address);
// enable interrupts return (_wire->endTransmission() == 0);
_read(0xFF00);
return isConnected();
} }
@ -79,8 +72,8 @@ uint8_t I2CKeyPad8x8::getKey()
} }
uint8_t I2CKeyPad8x8::getLastKey() uint8_t I2CKeyPad8x8::getLastKey()
{ {
return _lastKey; return _lastKey;
}; };
@ -94,22 +87,15 @@ bool I2CKeyPad8x8::isPressed()
} }
bool I2CKeyPad8x8::isConnected()
{
_wire->beginTransmission(_address);
return (_wire->endTransmission() == 0);
}
uint8_t I2CKeyPad8x8::getChar() uint8_t I2CKeyPad8x8::getChar()
{ {
return _keyMap[getKey()]; return _keyMap[getKey()];
}; };
uint8_t I2CKeyPad8x8::getLastChar() uint8_t I2CKeyPad8x8::getLastChar()
{ {
return _keyMap[_lastKey]; return _keyMap[_lastKey];
}; };
@ -143,5 +129,5 @@ uint16_t I2CKeyPad8x8::_read(uint16_t mask)
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,7 +2,7 @@
// //
// FILE: I2CKeyPad8x8.h // FILE: I2CKeyPad8x8.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.1 // VERSION: 0.2.0
// PURPOSE: Arduino library for 8x8 or smaller KeyPad connected to an I2C PCF8575. // PURPOSE: Arduino library for 8x8 or smaller KeyPad connected to an I2C PCF8575.
// URL: https://github.com/RobTillaart/I2CKeyPad // URL: https://github.com/RobTillaart/I2CKeyPad
@ -11,7 +11,7 @@
#include "Wire.h" #include "Wire.h"
#define I2C_KEYPAD8x8_LIB_VERSION (F("0.1.1")) #define I2C_KEYPAD8x8_LIB_VERSION (F("0.2.0"))
#define I2C_KEYPAD8x8_NOKEY 64 #define I2C_KEYPAD8x8_NOKEY 64
#define I2C_KEYPAD8x8_FAIL 65 #define I2C_KEYPAD8x8_FAIL 65
@ -22,17 +22,14 @@ class I2CKeyPad8x8
public: public:
I2CKeyPad8x8(const uint8_t deviceAddress, TwoWire *wire = &Wire); I2CKeyPad8x8(const uint8_t deviceAddress, TwoWire *wire = &Wire);
#if defined(ESP8266) || defined(ESP32)
bool begin(uint8_t sda, uint8_t scl);
#endif
bool begin(); bool begin();
bool isConnected();
// get raw key's 0..65 // get raw key's 0..65
uint8_t getKey(); uint8_t getKey();
uint8_t getLastKey(); uint8_t getLastKey();
bool isPressed(); bool isPressed();
bool isConnected();
// get 'translated' keys // get 'translated' keys
// user must load KeyMap, there is no check. // user must load KeyMap, there is no check.
@ -52,5 +49,5 @@ protected:
}; };
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,8 +2,11 @@
[![Arduino CI](https://github.com/RobTillaart/I2CKeyPad8x8/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino CI](https://github.com/RobTillaart/I2CKeyPad8x8/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/I2CKeyPad8x8/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/I2CKeyPad8x8/actions/workflows/arduino-lint.yml) [![Arduino-lint](https://github.com/RobTillaart/I2CKeyPad8x8/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/I2CKeyPad8x8/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/I2CKeyPad8x8/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/I2CKeyPad8x8/actions/workflows/jsoncheck.yml) [![JSON check](https://github.com/RobTillaart/I2CKeyPad8x8/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/I2CKeyPad8x8/actions/workflows/jsoncheck.yml)
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/I2CKeyPad8x8.svg)](https://github.com/RobTillaart/I2CKeyPad8x8/issues)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/I2CKeyPad8x8/blob/master/LICENSE) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/I2CKeyPad8x8/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/I2CKeyPad8x8.svg?maxAge=3600)](https://github.com/RobTillaart/I2CKeyPad8x8/releases) [![GitHub release](https://img.shields.io/github/release/RobTillaart/I2CKeyPad8x8.svg?maxAge=3600)](https://github.com/RobTillaart/I2CKeyPad8x8/releases)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/I2CKeyPad8x8.svg)](https://registry.platformio.org/libraries/robtillaart/I2CKeyPad8x8)
# I2CKeyPad8x8 # I2CKeyPad8x8
@ -18,13 +21,19 @@ EXPERIMENTAL (first tests ==> OK)
The I2CKeyPad8x8 library implements the reading of a 8x8 keypad by means of a PCF8575. The I2CKeyPad8x8 library implements the reading of a 8x8 keypad by means of a PCF8575.
Smaller keypads, meaning less columns or rows (e.g. 5x4) can be read with it too. Smaller keypads, meaning less columns or rows (e.g. 5x4) can be read with it too.
Relates to https://github.com/RobTillaart/I2CKeyPad. which is an version using PCF8574. #### Related
Relates strongly to https://github.com/RobTillaart/I2CKeyPad. which is an 8x8 version using **PCF8574**.
- https://github.com/RobTillaart/AnalogKeypad
- https://github.com/RobTillaart/I2CKeyPad8x8
## Connection ## Connection
The PCF8575 is connected between the processor and the (default) 8x8 keypad. The PCF8575 is connected between the processor and the (default) 8x8 keypad.
See the conceptual schema below. See the conceptual schema below.
It might take some trying to get the correct pins connected.
``` ```
PROC PCF8575 KEYPAD PROC PCF8575 KEYPAD
@ -45,12 +54,18 @@ See the conceptual schema below.
## Interface ## Interface
```cpp
#include "I2CKeyPad8x8.h"
```
#### Base
- **I2CKeyPad8x8(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** - **I2CKeyPad8x8(const uint8_t deviceAddress, TwoWire \*wire = &Wire)**
The constructor sets the device address and optionally The constructor sets the device address and optionally
allows to selects the I2C bus to use. allows to selects the I2C bus to use.
- **bool begin()** The return value shows if the PCF8575 with the given address is connected properly. - **bool begin()** The return value shows if the PCF8575 with the given address is connected properly.
- **bool begin(uint8_t sda, uint8_t scl)** for ESP32. Call wire.begin() first!
The return value shows if the PCF8575 with the given address is connected properly.
- **bool isConnected()** returns false if the PCF8575 cannot be connected to. - **bool isConnected()** returns false if the PCF8575 cannot be connected to.
- **uint8_t getKey()** Returns default 0..63 for regular keys, - **uint8_t getKey()** Returns default 0..63 for regular keys,
Returns 64 if no key is pressed and 65 in case of an error. Returns 64 if no key is pressed and 65 in case of an error.
@ -81,7 +96,7 @@ The length is **NOT** checked upon loading (as it may contain a NULL char).
#### Basic working #### Basic working
After the **keypad.begin()** the sketch calls the **keyPad.getKey()** to read values from the keypad. After the **keypad.begin()** the sketch calls the **keyPad.getKey()** to read values from the keypad.
- If no key is pressed **I2CKeyPad8x8_NOKEY** code (16) is returned. - If no key is pressed **I2C_KEYPAD8x8_NOKEY** code (16) is returned.
- If the read value is not valid, e.g. two keys pressed, **I2CKeyPad8x8_FAIL** code (17) is returned. - If the read value is not valid, e.g. two keys pressed, **I2CKeyPad8x8_FAIL** code (17) is returned.
- Otherwise a number 0..63 is returned. - Otherwise a number 0..63 is returned.
@ -107,16 +122,29 @@ See examples
## Future ## Future
#### must #### Must
- update documentation
- update documentation
- keep in sync with **I2CKeyPad** as much as possible.
#### Should
#### should
- test extensively - test extensively
- basic working (OK) - basic working (OK)
- interrupts - interrupts
- keymapping - keymapping
- performance - performance
- keep in sync with **I2CKeyPad** as much as possible.
#### would #### Could
#### Wont
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,

View File

@ -57,4 +57,4 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -6,14 +6,15 @@ I2CKeyPad8x8 KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
begin KEYWORD2 begin KEYWORD2
isConnected() KEYWORD2
getKey KEYWORD2 getKey KEYWORD2
getLastKey KEYWORD2 getLastKey KEYWORD2
isPressed KEYWORD2 isPressed KEYWORD2
isConnected() KEYWORD2
loadKeyMap KEYWORD2
getChar KEYWORD2 getChar KEYWORD2
getLastChar KEYWORD2 getLastChar KEYWORD2
loadKeyMap KEYWORD2
# Instances (KEYWORD2) # Instances (KEYWORD2)
@ -21,8 +22,7 @@ getLastChar KEYWORD2
# Constants (LITERAL1) # Constants (LITERAL1)
I2C_KEYPAD8x8_LIB_VERSION LITERAL1 I2C_KEYPAD8x8_LIB_VERSION LITERAL1
I2C_KEYPAD8x8_NOKEY LITERAL1 I2C_KEYPAD8x8_NOKEY LITERAL1
I2C_KEYPAD8x8_FAIL LITERAL1 I2C_KEYPAD8x8_FAIL LITERAL1
I2C_KEYPAD8x8_NOKEY LITERAL1
I2C_KEYPAD8x8_FAIL LITERAL1

View File

@ -15,9 +15,9 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/I2CKeyPad8x8.git" "url": "https://github.com/RobTillaart/I2CKeyPad8x8.git"
}, },
"version": "0.1.1", "version": "0.2.0",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "*",
"platforms": "*", "platforms": "*",
"headers": "I2CKeyPad8x8.h" "headers": "I2CKeyPad8x8.h"
} }

View File

@ -1,5 +1,5 @@
name=I2CKeyPad8x8 name=I2CKeyPad8x8
version=0.1.1 version=0.2.0
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for a KeyPad connected to a PCF8575. sentence=Arduino library for a KeyPad connected to a PCF8575.