scan a 3x4 keypad with softaware pulldown resistors by polling it continuously.

Fork of keypad by Dimiter K

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers keypad3x4.h Source File

keypad3x4.h

00001 
00002 
00003 //Dimiter Kentri update
00004 
00005 
00006 /*   Copyright (c) 2010 Dimiter Kentri
00007 
00008 Permission is hereby granted, free of charge, to any person obtaining a copy
00009 of this software and associated documentation files (the "Software"), to deal
00010 in the Software without restriction, including without limitation the rights
00011 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012 copies of the Software, and to permit persons to whom the Software is
00013 furnished to do so, subject to the following conditions:
00014 
00015 The above copyright notice and this permission notice shall be included in
00016 all copies or substantial portions of the Software.
00017 
00018 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024 THE SOFTWARE.
00025 */
00026 
00027 /*Simple example
00028 
00029 #include "mbed.h"
00030 #include "keypad.h"
00031       
00032 Serial pc(USBTX, USBRX); 
00033 Keypad telepad(p13,p14,p15,p17,p18,p19,p20);
00034                     
00035 int main(void){
00036   char key;
00037   pc.printf("Enter codes\n\r");
00038   while(1){ 
00039     key = telepad.getKey(); 
00040     if(key != KEY_RELEASED){
00041     pc.printf("%c\n",key);
00042     wait(0.6);
00043      }
00044     }
00045 }*/
00046 
00047 #ifndef KEYPAD3x4_H
00048 #define KEYPAD3x4_H
00049 
00050 #include "DigitalIn.h"
00051 #include "BusOut.h"
00052 
00053 
00054 namespace mbed
00055 {
00056     const char NO_KEY = '\0';
00057     #define KEY_RELEASED NO_KEY
00058     const int keys[12] = {'1','2','3','4','5','6','7','8','9','*','0','#',};                  
00059     class Keypad
00060     {    
00061         public:
00062             Keypad(PinName col1,PinName col2,PinName col3,PinName row1,PinName row2,PinName row3,PinName row4);
00063             char getKey();
00064         protected:
00065             int getKeyIndex();
00066             DigitalIn _col1,_col2,_col3;    
00067             BusOut _rows;
00068     };
00069 }
00070 #endif