Serial Wombat Arduino Library
Public Member Functions | Public Attributes | Protected Attributes | List of all members
SerialWombatMatrixKeypad Class Reference

A class for the Serial Wombat SW18AB chips which scans matrix keypads up to 4x4. More...

#include <SerialWombatMatrixKeypad.h>

Inheritance diagram for SerialWombatMatrixKeypad:

Public Member Functions

 SerialWombatMatrixKeypad (SerialWombatChip &serialWombat)
 Constructor for the SerialWombatMatrixKeypad class.
More...
 
int16_t begin (uint8_t controlPin, uint8_t row0pin, uint8_t row1pin, uint8_t row2pin, uint8_t row3pin, uint8_t column0pin, uint8_t column1pin, uint8_t column2pin, uint8_t column3pin, uint8_t bufferMode=0, uint8_t queueMode=1)
 
int16_t writeQueueMask (uint16_t mask)
 Set a binary mask for which keys are added to Queue. More...
 
int available ()
 Queries the SerialWombatMatrixKeypad for number bytes available to read. More...
 
int read ()
 Reads a byte from the SerialWombatMatrixKeypad queue. More...
 
void flush ()
 Discard all bytes from the SerialWombatMatrixKeypad queue. More...
 
int peek ()
 Query the SerialWombatMatrixKeypad queue for the next avaialble byte, but don't remove it from the queue. More...
 
size_t write (uint8_t data)
 Write a byte to the SerialWombatMatrixKeypad queue (Does Nothing) More...
 
size_t write (const uint8_t *buffer, size_t size)
 Write bytes to the SerialWombatMatrixKeypad queue (Does nothing) More...
 
int availableForWrite ()
 Number of bytes avaialble to write to SerialWombatMatrixKeypad queue. Returns 0. More...
 
size_t readBytes (char *buffer, size_t length)
 Reads a specified number of bytes from the SerialWombatMatrixKeypad queue queue. More...
 
void setTimeout (long timeout_mS)
 implemented to fulfill Stream requirement. More...
 
SerialWombatMatrixKeypad operator= (SerialWombatMatrixKeypad &kp)
 used to allow reference copy. Not for user use. More...
 

Public Attributes

SerialWombatChip_sw
 
uint8_t _pin = 255
 

Protected Attributes

uint32_t timeout = 1
 

Detailed Description

A class for the Serial Wombat SW18AB chips which scans matrix keypads up to 4x4.

A Tutorial video is avaialble:

https://youtu.be/hxLda6lBWNg

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.

Constructor & Destructor Documentation

◆ SerialWombatMatrixKeypad()

SerialWombatMatrixKeypad::SerialWombatMatrixKeypad ( SerialWombatChip serialWombat)
inline

Constructor for the SerialWombatMatrixKeypad class.

Parameters
serialWombatThe Serial Wombat Chip on which the SerialWombatUART instance will run.

Member Function Documentation

◆ available()

int SerialWombatMatrixKeypad::available ( )
inline

Queries the SerialWombatMatrixKeypad for number bytes available to read.

Returns
Number of bytes available to read.

◆ availableForWrite()

int SerialWombatMatrixKeypad::availableForWrite ( )
inline

Number of bytes avaialble to write to SerialWombatMatrixKeypad queue. Returns 0.

Returns
Zero. Writes are not suppored.

◆ begin()

int16_t SerialWombatMatrixKeypad::begin ( uint8_t  controlPin,
uint8_t  row0pin,
uint8_t  row1pin,
uint8_t  row2pin,
uint8_t  row3pin,
uint8_t  column0pin,
uint8_t  column1pin,
uint8_t  column2pin,
uint8_t  column3pin,
uint8_t  bufferMode = 0,
uint8_t  queueMode = 1 
)
inline

◆ flush()

void SerialWombatMatrixKeypad::flush ( )
inline

Discard all bytes from the SerialWombatMatrixKeypad queue.

◆ operator=()

SerialWombatMatrixKeypad SerialWombatMatrixKeypad::operator= ( SerialWombatMatrixKeypad kp)
inline

used to allow reference copy. Not for user use.

◆ peek()

int SerialWombatMatrixKeypad::peek ( )
inline

Query the SerialWombatMatrixKeypad queue for the next avaialble byte, but don't remove it from the queue.

Returns
A byte from 0-255, or -1 if no bytes were avaialble

◆ read()

int SerialWombatMatrixKeypad::read ( )
inline

Reads a byte from the SerialWombatMatrixKeypad queue.

Returns
A byte from 0-255, or -1 if no bytes were avaialble

◆ readBytes()

size_t SerialWombatMatrixKeypad::readBytes ( char *  buffer,
size_t  length 
)
inline

Reads a specified number of bytes from the SerialWombatMatrixKeypad queue queue.

Parameters
bufferAn array into which to put received bytes
lengthThe maximum number of bytes to be received
Returns
the number of bytes written to buffer

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.

◆ setTimeout()

void SerialWombatMatrixKeypad::setTimeout ( long  timeout_mS)
inline

implemented to fulfill Stream requirement.

◆ write() [1/2]

size_t SerialWombatMatrixKeypad::write ( const uint8_t *  buffer,
size_t  size 
)
inline

Write bytes to the SerialWombatMatrixKeypad queue (Does nothing)

Parameters
bufferAn array of uint8_t bytes to send
sizethe number of bytes to send
Returns
the number of bytes sent

This function exists to fully implement the Stream class. It throws away the bytes.

◆ write() [2/2]

size_t SerialWombatMatrixKeypad::write ( uint8_t  data)
inline

Write a byte to the SerialWombatMatrixKeypad queue (Does Nothing)

Parameters
dataByte to write
Returns
Number of bytes written

This function exists to fully implement the Stream class. It throws away the byte.

◆ writeQueueMask()

int16_t SerialWombatMatrixKeypad::writeQueueMask ( uint16_t  mask)
inline

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
maskA 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.

Member Data Documentation

◆ _pin

uint8_t SerialWombatMatrixKeypad::_pin = 255

◆ _sw

SerialWombatChip& SerialWombatMatrixKeypad::_sw

◆ timeout

uint32_t SerialWombatMatrixKeypad::timeout = 1
protected