Closed adrianbn closed 4 years ago
The Keypad library does not work using interrupts. It depends on being called repeatedly from loop( ) and debouncing key presses using the millis( ) timer. The PCF8574 interrupt output would be asserted every time any pin changes state--when the column pins are driven low during scanning--but then it will be cleared when the row pins are all read.
The key mapping is already done by Keypad, you don't need to find the row and column and then look up the key in keymap, getKey( ) returns the looked-up value.
I guess I would ask what you want an interrupt for? If it's to do something when ANY key is pressed, the library has that capability; in setup( ), add the statement keypad.addEventListener(keypadEvent); as illustrated in the EventKeypad examples.
As far as I understand it keypad.addEventListener(keypadEvent)
still requires constantly calling getKey()
in the loop
function. I'm trying to remove some of the things I do in the loop
and increase the responsiveness of the keypad by getting an interrupt any time a key is pressed, then figure out which key was it.
The code I showed above does operate the keypad using interrupts, but it is using pin_read
and pin_write
directly to get the key being pressed instead of invoking getKey()
. Even though interrupts are not supported by the Keypad library, I was curious if it was something Keypad_I2C would support since PCF8574 provides the necessary elements to do so.
Yes, the EventListener does still require calling getKey, or getKeys.
I missed your intention to just use the port access functions. If you don't need Keypad's capabilities, take a look at my shrPort libraries: shrPort.
But, as your code shows, to use a matrix keypad, you still have to generate the interrupt by scanning the columns (or rows) and you'd want to incorporate some debouncing, both already included with Keypad. Still by thus stripping out features, you may make the code smaller and more responsive.
I'll be looking at shrPort, thanks! Closing this as answered!
Hi,
thanks for this library, it's been lifesaving so far :) I'm trying to get a matrix keypad connected via PCF8574 to work with interrupts and finding it requires direct pin access to the underlying PCF8574 when using this library. I was expecting (clearly wrongly) that the INT pin of the PCF8574 would be pulled LOW whenever a key was pressed on the matrix keypad, but it seems to always be HIGH by default. I think the library is setting all pins HIGH on init thus disabling the interrupt function?
To be able to read a key pressed via interrupts I'm doing the following:
Ignoring the lack of debouncing and code quality, this is obviously not so great since I'm effectively bypassing the library and I have to deal with key mapping myself once row / column has been found. Is there a way to utilize interrupts that I'm missing?
Cheers, Adrian