Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of keypad by
keypad3x4.cpp
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 #include "mbed.h" 00028 #include "keypad3x4.h" 00029 00030 using namespace mbed; 00031 00032 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) 00033 { 00034 _col1.mode(PullUp); 00035 _col2.mode(PullUp); 00036 _col3.mode(PullUp); 00037 } 00038 00039 int Keypad::getKeyIndex() 00040 { 00041 _rows = 0; 00042 for(int i=0; i<4; i++) 00043 { 00044 _rows = 1 << i; 00045 for(int j=0; j<4;j++) 00046 { 00047 if (_col1) 00048 return 1+(i*3); 00049 else if (_col2) 00050 return 2+(i*3); 00051 else if (_col3) 00052 return 3+(i*3); 00053 } 00054 } 00055 return 11; 00056 } 00057 00058 char Keypad::getKey() 00059 { 00060 int k = getKeyIndex(); 00061 if(k != 11) 00062 return keys[k-1]; 00063 else 00064 return 0; 00065 }
Generated on Sun Jul 24 2022 15:54:25 by
1.7.2
