-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiples digits when press any key #22
Comments
Sorry for the long delay, I missed the notifications. |
@joaouzeda Thanks for reporting anyway, appreciated! |
It sounds like a bouncing key, did you get the same digit multiple times? |
A generic solution could be a parameter (or internal variable), configurable in the interface of the library. uint8_t I2CKeyPad::_getKey4x4(int debounceDelay = 0) // default 0 for backwards compatibility
{
// key = row + 4 x col
uint8_t key = 0;
// mask = 4 rows as input pull up, 4 columns as output
uint8_t rows = _read(0xF0);
// check if single line has gone low.
if (rows == 0xF0) return I2C_KEYPAD_NOKEY;
else if (rows == 0xE0) key = 0;
else if (rows == 0xD0) key = 1;
else if (rows == 0xB0) key = 2;
else if (rows == 0x70) key = 3;
else return I2C_KEYPAD_FAIL;
// 4 columns as input pull up, 4 rows as output
uint8_t cols = _read(0x0F);
// check if single line has gone low.
if (cols == 0x0F) return I2C_KEYPAD_NOKEY;
else if (cols == 0x0E) key += 0;
else if (cols == 0x0D) key += 4;
else if (cols == 0x0B) key += 8;
else if (cols == 0x07) key += 12;
else return I2C_KEYPAD_FAIL;
_lastKey = key;
if (debounceDelay ) delay(debounceDelay ); // call only if debounceDelay > 0
return key; // 0..15
} Another option could be to have a static timestamp that checks if the last call was less than e.g. 50 millis ago. |
mmm, debounce delay need to work for all four supported key layouts. Solution should be implemented in a higher layer. something like: uint8_t I2CKeyPad::getKey()
{
if (millis() - lastCall) < threshold return TOOFAST
uint8_t _key = 0;
if (_mode == I2C_KEYPAD_5x3) _key = _getKey5x3();
else if (_mode == I2C_KEYPAD_6x2) _key =_getKey6x2();
else if (_mode == I2C_KEYPAD_8x1) _key = _getKey8x1();
else _key = _getKey4x4(); // default.
return _key;
} |
Solution implemented in pull request #23 (snippet of new readme.md) Debouncing thresholdExperimental since version 0.4.1, the library implements a debounce threshold. // value in microseconds, max 65535 us
If a debounce threshold is set, and getKey() is called too fast, |
Thank for your answer! |
I was having a problem that when a key was pressed it sent multiple digits, my solution was to put a delay in the _getKey4x4() function, as I put below
(updated syntax highlighting)
The text was updated successfully, but these errors were encountered: