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.
main.cpp
00001 #include "mbed.h" 00002 00003 BusOut LED_Disp(p7,p11,p9,p8,p5,p6,p10,p12); 00004 00005 00006 00007 DigitalOut col1 (p26); // pin 4 on keypad 00008 DigitalOut col2 (p28); // pin 2 00009 DigitalOut col3 (p24); // pin 6 00010 00011 DigitalIn row1 (p27); // pin 3 00012 DigitalIn row2 (p22); // pin 8 00013 DigitalIn row3 (p23); // pin 7 00014 DigitalIn row4 (p25); // pin 5 00015 00016 char keypad(void); // declare keypad function will return character pressed 00017 void DisplayNumber(int); // Declare functio to display number on seven seg 00018 00019 int main() 00020 { 00021 char kp_val = ' '; // character that changes when the key is pressed, has initial value 00022 00023 LED_Disp = 0xFF; 00024 00025 while(1) 00026 { 00027 kp_val = keypad(); 00028 00029 if(kp_val!= ' ') // poll keypad and check if any value is pressed 00030 { 00031 if(kp_val=='*') LED_Disp = ~0x63; 00032 if(kp_val=='#') LED_Disp = ~0x5C; 00033 00034 if(kp_val>='0' && kp_val<='9') 00035 DisplayNumber(kp_val-48); // subtract 48 to change ASCII into number 00036 00037 kp_val=' '; // reset keypad_char 00038 } 00039 wait(0.1); 00040 } 00041 } 00042 00043 00044 char keypad(void) 00045 { 00046 col1=1; 00047 col2=0; 00048 col3=0; 00049 00050 if(row1==1) 00051 { 00052 while(row1==1){} 00053 00054 col1=0; 00055 col2=0; 00056 col3=0; 00057 return('1'); 00058 } 00059 else if(row2==1) 00060 { 00061 while (row2==1){} 00062 00063 col1=0; 00064 col2=0; 00065 col3=0; 00066 return('4'); 00067 } 00068 else if(row3==1) 00069 { 00070 while (row3==1){} 00071 00072 col1=0; 00073 col2=0; 00074 col3=0; 00075 return('7'); 00076 } 00077 else if(row4==1) 00078 { 00079 while(row4==1){} 00080 00081 col1=0; 00082 col2=0; 00083 col3=0; 00084 return('*'); 00085 } 00086 00087 col1=0; 00088 col2=1; 00089 col3=0; 00090 00091 if(row1==1) 00092 { 00093 while(row1==1){} 00094 00095 col1=0; 00096 col2=0; 00097 col3=0; 00098 return('2'); 00099 } 00100 else if(row2==1) 00101 { 00102 while (row2==1){} 00103 00104 col1=0; 00105 col2=0; 00106 col3=0; 00107 return('5'); 00108 } 00109 else if(row3==1) 00110 { 00111 while (row3==1){} 00112 00113 col1=0; 00114 col2=0; 00115 col3=0; 00116 return('8'); 00117 } 00118 else if(row4==1) 00119 { 00120 while(row4==1){} 00121 00122 col1=0; 00123 col2=0; 00124 col3=0; 00125 return('0'); 00126 } 00127 00128 col1=0; 00129 col2=0; 00130 col3=1; 00131 00132 if(row1==1) 00133 { 00134 while(row1==1){} 00135 00136 col1=0; 00137 col2=0; 00138 col3=0; 00139 return('3'); 00140 } 00141 else if(row2==1) 00142 { 00143 while (row2==1){} 00144 00145 col1=0; 00146 col2=0; 00147 col3=0; 00148 return('6'); 00149 } 00150 else if(row3==1) 00151 { 00152 while (row3==1){} 00153 00154 col1=0; 00155 col2=0; 00156 col3=0; 00157 return('9'); 00158 } 00159 else if (row4==1) 00160 { 00161 while(row4==1){} 00162 00163 col1=0; 00164 col2=0; 00165 col3=0; 00166 return('#'); 00167 } 00168 00169 col1=0; 00170 col2=0; 00171 col3=0; 00172 00173 return(' '); 00174 } 00175 00176 void DisplayNumber(int num) 00177 { 00178 switch(num) 00179 { 00180 case 0: 00181 LED_Disp = ~0x3F; 00182 break; 00183 case 1: 00184 LED_Disp = ~0x06; 00185 break; 00186 case 2: 00187 LED_Disp = ~0x5B; 00188 break; 00189 case 3: 00190 LED_Disp = ~0x4F; 00191 break; 00192 case 4: 00193 LED_Disp = ~0x66; 00194 break; 00195 case 5: 00196 LED_Disp = ~0x6D; 00197 break; 00198 case 6: 00199 LED_Disp = ~0x7D; 00200 break; 00201 case 7: 00202 LED_Disp = ~0x07; 00203 break; 00204 case 8: 00205 LED_Disp = ~0x7F; 00206 break; 00207 case 9: 00208 LED_Disp = ~0x67; 00209 break; 00210 case 10: //# 00211 LED_Disp = ~0x5c; 00212 break; 00213 case 11: //* 00214 LED_Disp = ~0x63; 00215 break; 00216 } 00217 } 00218
Generated on Sun Jul 24 2022 08:53:52 by
