Class library for a 4x4 keypad connected to a MCP23008 I2C IO Expander.

Embed: (wiki syntax)

« Back to documentation index

MCP23008_Keypad Class Reference

MCP23008_Keypad Class Reference

Class library for a 4x4 keypad connected to a MCP23008 I2C IO Expander. More...

#include <MCP23008_Keypad.h>

Public Member Functions

 MCP23008_Keypad (PinName SDApin, PinName SCLpin, int MCP23008Address)
 Create a MCP23008_Keypad object.
char ReadKey ()
 Returns which key is currently is pressed.

Detailed Description

Class library for a 4x4 keypad connected to a MCP23008 I2C IO Expander.

The Keypad is assumed to be connected to the MCP23008 as follows:

GP7 -> ROW4; GP6 -> ROW3; GP5 -> ROW2; GP4 -> ROW1; GP3 -> COL4; GP2 -> COL3; GP1 -> COL2; GP0 -> COL1

Example:

 #include "mbed.h"
 #include "MCP23008_Keypad.h"

 MCP23008_Keypad keypad(PB_9, PB_6, 0x42);

 int main() {
     char rcv;
     int released = 1;

     while(1){
         rcv = keypad.ReadKey();                 //read the current key pressed

         if(rcv == '\0')
             released = 1;                       //set the flag when all keys are released
            
         if((rcv != '\0') && (released == 1)) {  //if a key is pressed AND previous key was released
             printf("%c\n", rcv);            
             released = 0;                       //clear the flag to indicate that key is still pressed
         }
     }
 }

Definition at line 63 of file MCP23008_Keypad.h.


Constructor & Destructor Documentation

MCP23008_Keypad ( PinName  SDApin,
PinName  SCLpin,
int  MCP23008Address 
)

Create a MCP23008_Keypad object.

Parameters:
SDApinI2C compatible pin used for connecting to the MCP23008's SDA pin
SCLpinI2C compatible pin used for connecting to the MCP23008's SCL pin
MCP23008AddressThe I2C address of the MCP23008 to which the Keypad is connected.

Definition at line 21 of file MCP23008_Keypad.cpp.


Member Function Documentation

char ReadKey (  )

Returns which key is currently is pressed.

Parameters:
None
Returns:
The character representation of the key being pressed. Returns '\0' if no key is pressed.

Definition at line 31 of file MCP23008_Keypad.cpp.