4x4 Keypad easy to use library that pollis the interface width pullups

Dependents:   4x4KeyBoardExample xoxokey 4x4KeyBoardExample ProgettoCassaforte ... more

Fork of keypad by Dimiter K

Simple library for reading a 4x4 keypad width at ability to use internal pullups

Import program

00001 #include "mbed.h"
00002 #include "keypad.h"
00003  
00004 Serial pc(USBTX, USBRX); 
00005 
00006  
00007 int main() {
00008                 //  c0   c1   c2   c3  r0   r1   r2   r3    
00009     Keypad keypad( PC_3,PC_2,PA_0,PA_1,PA_4,PB_0,PC_1,PC_0 );
00010        
00011     keypad.enablePullUp();
00012     char key;
00013     pc.printf("Please touch a key on the keypad\n\r");
00014     while (1) 
00015     {
00016          key = keypad.getKey();    
00017          if(key != KEY_RELEASED)
00018          {
00019              pc.printf("%c\r\n",key);
00020              wait(0.6);
00021          }
00022     }
00023 }

Import library

Public Member Functions

Keypad (PinName col0, PinName col1, PinName col2, PinName col3, PinName row0, PinName row1, PinName row2, PinName row3)
Create a 4x4 (col, row) or 4x4 keypad interface
.
char getKey ()
Returns the letter of the pressed key
.
bool getKeyPressed ()
Detects if any key was pressed.
void enablePullUp ()
Enables internal PullUp resistors on the coloums pins.

Protected Member Functions

int getKeyIndex ()
return the index value representating the pressed key

Committer:
DimiterK
Date:
Sat Nov 06 14:36:22 2010 +0000
Revision:
0:1fa357ea3fcc
Child:
1:fa689a04c361

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DimiterK 0:1fa357ea3fcc 1 /* Copyright (c) 2010 Dimiter Kentri
DimiterK 0:1fa357ea3fcc 2
DimiterK 0:1fa357ea3fcc 3 Permission is hereby granted, free of charge, to any person obtaining a copy
DimiterK 0:1fa357ea3fcc 4 of this software and associated documentation files (the "Software"), to deal
DimiterK 0:1fa357ea3fcc 5 in the Software without restriction, including without limitation the rights
DimiterK 0:1fa357ea3fcc 6 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
DimiterK 0:1fa357ea3fcc 7 copies of the Software, and to permit persons to whom the Software is
DimiterK 0:1fa357ea3fcc 8 furnished to do so, subject to the following conditions:
DimiterK 0:1fa357ea3fcc 9
DimiterK 0:1fa357ea3fcc 10 The above copyright notice and this permission notice shall be included in
DimiterK 0:1fa357ea3fcc 11 all copies or substantial portions of the Software.
DimiterK 0:1fa357ea3fcc 12
DimiterK 0:1fa357ea3fcc 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
DimiterK 0:1fa357ea3fcc 14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
DimiterK 0:1fa357ea3fcc 15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
DimiterK 0:1fa357ea3fcc 16 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
DimiterK 0:1fa357ea3fcc 17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
DimiterK 0:1fa357ea3fcc 18 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
DimiterK 0:1fa357ea3fcc 19 THE SOFTWARE.
DimiterK 0:1fa357ea3fcc 20 */
DimiterK 0:1fa357ea3fcc 21
DimiterK 0:1fa357ea3fcc 22 #ifndef KEYPAD_H
DimiterK 0:1fa357ea3fcc 23 #define KEYPAD_H
DimiterK 0:1fa357ea3fcc 24
DimiterK 0:1fa357ea3fcc 25 #include "DigitalIn.h"
DimiterK 0:1fa357ea3fcc 26 #include "BusOut.h"
DimiterK 0:1fa357ea3fcc 27
DimiterK 0:1fa357ea3fcc 28
DimiterK 0:1fa357ea3fcc 29 namespace mbed{
DimiterK 0:1fa357ea3fcc 30
DimiterK 0:1fa357ea3fcc 31 const char NO_KEY = '\0';
DimiterK 0:1fa357ea3fcc 32 #define KEY_RELEASED NO_KEY
DimiterK 0:1fa357ea3fcc 33
DimiterK 0:1fa357ea3fcc 34
DimiterK 0:1fa357ea3fcc 35
DimiterK 0:1fa357ea3fcc 36 const int keys[16] = {'1','2','3','A',
DimiterK 0:1fa357ea3fcc 37 '4','5','6','B',
DimiterK 0:1fa357ea3fcc 38 '7','8','9','C',
DimiterK 0:1fa357ea3fcc 39 '*','0','#','D'};
DimiterK 0:1fa357ea3fcc 40
DimiterK 0:1fa357ea3fcc 41 class Keypad{
DimiterK 0:1fa357ea3fcc 42 public:
DimiterK 0:1fa357ea3fcc 43 Keypad(PinName col1, PinName col2, PinName col3, PinName col4, PinName row1,PinName row2, PinName row3, PinName row4);
DimiterK 0:1fa357ea3fcc 44 int getKeyIndex();
DimiterK 0:1fa357ea3fcc 45 char getKey();
DimiterK 0:1fa357ea3fcc 46
DimiterK 0:1fa357ea3fcc 47 protected:
DimiterK 0:1fa357ea3fcc 48 DigitalIn _col1,_col2,_col3,_col4;
DimiterK 0:1fa357ea3fcc 49 BusOut _rows;
DimiterK 0:1fa357ea3fcc 50 };
DimiterK 0:1fa357ea3fcc 51
DimiterK 0:1fa357ea3fcc 52 }
DimiterK 0:1fa357ea3fcc 53 #endif