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

Fork of keypad by Dimiter K

Committer:
fangoman91
Date:
Fri May 08 06:50:54 2015 +0000
Revision:
1:b8305e120e11
Dimiter Kentry update. Eliminate one column and add software pulldown resistors

Who changed what in which revision?

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