The class inherits from the Arduino Stream class, so queued kepad presses can be read like a Serial port.
This class allows the user to declare up to 4 row and 4 column pins which are strobed continuously to read up to 16 buttons. The Serial Wombat chip's internal pull-up resistors are used so no additional hardware is necesary. Standard matrix keypads can be attached directly to the Serial Wombat chip pins. All Serial Wombat 18AB chip pins can be used in any combination or order.
Results can be returned to the host as a binary 16 bit number indicating the state of 16 buttons, as an index indicating which button is currently pressed (0 for Col 0 Row 0, 3 for Col 3 Row 3 and 12 for Col 0 Row 3, or as ASCII values which assume a standard keypad layout.
Index mode:
|0 1 2 3 |
|4 5 6 7 |
|8 9 10 11|
|12 13 14 15|
With 16 being used for no current press, depending on mode setting
Ascii Mode:
|1 2 3 A|
|4 5 6 B|
|7 8 9 C|
|* 0 # D|
Note that the key indexes remain the same regardless of how many rows and columns are enabled.
The Serial Wombat 18AB firmware also keeps track of button transition counts and time since last transition for all 16 buttons. In this way each key of the keypad can be treated equivalently to a SerialWombatDebouncedInput class when encapsulated in a SerialWombatMatrixInput class. See the documentation on this class and Arduino examples for details.
The 16 Bit public data presented internally to other Serial Wombat pins and through the SerialWombatChip.readPublicData method can be configured to present the binary state of 16 buttons, the last button index pressed, the last button index pressed or 16 if no button is pressed, or ASCII of last button pressed.
This function will read bytes from the SerialWombatMatrixKeypad queue into buffer. If 'length' characters are not available to read then the value returned will be less than length.
Set a binary mask for which keys are added to Queue.
This commands allows exclusion of keys from being queued. This can be useful if, for instance, only the numeric keys of a keypad are to be added to the queue (excluding #,*, ABCD, etc)
Parameters
mask
A 16 bit bitmap where a 1 allows queuing of that key index and a 0 does not. Index 0 is LSB. For instance, for a typical Phone/ABCD keypad, a mask of 0x2777 would allow the numeric keys to be added to the queue but would exclude ABCD#* .
Returns
Returns 0 or higher if successfully set or a negative error code otherwise.