Class library for a polling-based 4x4 keypad.

Dependents:   LCD kbdlcdkl25z control_onoff control_onoff ... more

Embed: (wiki syntax)

« Back to documentation index

Keypad Class Reference

Keypad Class Reference

Class library for a polling-based 4x4 keypad. More...

#include <Keypad.h>

Public Member Functions

 Keypad (PinName col1, PinName col2, PinName col3, PinName col4, PinName row1, PinName row2, PinName row3, PinName row4)
 Create a Keypad object.
char ReadKey ()
 Returns the letter of the key pressed.

Detailed Description

Class library for a polling-based 4x4 keypad.

Example:

 #include "mbed.h"
 #include "Keypad.h"

 Keypad kpad(PE_15, PE_14, PE_13, PE_12, PE_11, PE_10, PE_9, PE_8);

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

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

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

Definition at line 60 of file Keypad.h.


Constructor & Destructor Documentation

Keypad ( PinName  col1,
PinName  col2,
PinName  col3,
PinName  col4,
PinName  row1,
PinName  row2,
PinName  row3,
PinName  row4 
)

Create a Keypad object.

Parameters:
col1..4DigitalOut (or BusOut) compatible pins for keypad Column data lines
row1..4DigitalIn (or BusIn) compatible pins for keypad Row data lines

Definition at line 21 of file Keypad.cpp.


Member Function Documentation

char ReadKey (  )

Returns the letter of the key pressed.

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

Definition at line 23 of file Keypad.cpp.