scan a 3x4 keypad with softaware pulldown resistors by polling it continuously.
Fork of keypad by
Diff: keypad3x4.h
- Revision:
- 1:b8305e120e11
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/keypad3x4.h Fri May 08 06:50:54 2015 +0000 @@ -0,0 +1,70 @@ + + +//Dimiter Kentri update + + +/* Copyright (c) 2010 Dimiter Kentri + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +/*Simple example + +#include "mbed.h" +#include "keypad.h" + +Serial pc(USBTX, USBRX); +Keypad telepad(p13,p14,p15,p17,p18,p19,p20); + +int main(void){ + char key; + pc.printf("Enter codes\n\r"); + while(1){ + key = telepad.getKey(); + if(key != KEY_RELEASED){ + pc.printf("%c\n",key); + wait(0.6); + } + } +}*/ + +#ifndef KEYPAD3x4_H +#define KEYPAD3x4_H + +#include "DigitalIn.h" +#include "BusOut.h" + + +namespace mbed +{ + const char NO_KEY = '\0'; + #define KEY_RELEASED NO_KEY + const int keys[12] = {'1','2','3','4','5','6','7','8','9','*','0','#',}; + class Keypad + { + public: + Keypad(PinName col1,PinName col2,PinName col3,PinName row1,PinName row2,PinName row3,PinName row4); + char getKey(); + protected: + int getKeyIndex(); + DigitalIn _col1,_col2,_col3; + BusOut _rows; + }; +} +#endif