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.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 #include <map> 00003 00004 //Initialize serial comms 00005 Serial pc(USBTX, USBRX); 00006 00007 //Initialize PMW 00008 PwmOut PWM1(p21); 00009 00010 00011 //Initialize Keypad I/O 00012 DigitalOut row1(p26); 00013 DigitalOut row2(p23); 00014 DigitalOut row3(p24); 00015 DigitalOut row4(p25); 00016 00017 DigitalIn col1(p20); 00018 DigitalIn col2(p19); 00019 DigitalIn col3(p18); 00020 DigitalIn col4(p17); 00021 Timer t1; 00022 00023 //map used for keypad 00024 map<int, char> keypadMap; 00025 00026 00027 //Map for keypad 00028 //First 4 bits corrospond to active column 00029 //Last 4 bits corrospond to active row 00030 void init(){ 00031 keypadMap[0x11]='1'; 00032 keypadMap[0x12]='2'; 00033 keypadMap[0x14]='3'; 00034 keypadMap[0x18]='A'; 00035 keypadMap[0x21]='4'; 00036 keypadMap[0x22]='5'; 00037 keypadMap[0x24]='6'; 00038 keypadMap[0x28]='B'; 00039 keypadMap[0x41]='7'; 00040 keypadMap[0x42]='8'; 00041 keypadMap[0x44]='9'; 00042 keypadMap[0x48]='C'; 00043 keypadMap[0x81]='*'; 00044 keypadMap[0x82]='0'; 00045 keypadMap[0x84]='#'; 00046 keypadMap[0x88]='D'; 00047 } 00048 00049 int main() { 00050 init(); 00051 //Initialize rows to 0 00052 row1 = 0; 00053 row2 = 0; 00054 row3 = 0; 00055 row4 = 0; 00056 t1.start(); 00057 int input = 0x00; 00058 while(1) { 00059 //make all rows 0 to add stability 00060 row1 = 0; 00061 row2 = 0; 00062 row3 = 0; 00063 row4 = 0; 00064 //Keep each led lit for 4ms 00065 switch(t1.read_ms()%4){ 00066 case 0: row1 = 1; 00067 input |= 0x10; 00068 break; 00069 case 1: row2 = 1; 00070 input |= 0x20; 00071 break; 00072 case 2: row3 = 1; 00073 input |= 0x40; 00074 break; 00075 case 3: row4 = 1; 00076 input |= 0x80; 00077 break; } 00078 //Pull the value from each column and check to see if 1 00079 if(col1 == 1) 00080 input |= 0x01; 00081 else if(col2 == 1) 00082 input |= 0x02; 00083 else if(col3 == 1) 00084 input |= 0x04; 00085 else if(col4 == 1) 00086 input |= 0x08; 00087 00088 char c = keypadMap[input]; //assign charcter based on input 00089 //Print to the terminal the character if available 00090 if(c != 0){ 00091 pc.printf("%c\r",c); //print input and char 00092 } 00093 //reset input 00094 input = 0x00; 00095 } 00096 }
Generated on Tue Jul 12 2022 23:15:23 by
1.7.2