Andrew Bell / Mbed 2 deprecated lab3_keypad

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
andrewbw01
Date:
Fri Feb 12 11:10:52 2021 +0000
Commit message:
working keypad

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 12 11:10:52 2021 +0000
@@ -0,0 +1,208 @@
+#include "mbed.h"
+
+BusOut LED_Disp(p7,p11,p9,p8,p5,p6,p10,p12);
+
+
+
+DigitalOut col1 (p26);       // pin 4 on keypad
+DigitalOut col2 (p28);       // pin 2
+DigitalOut col3 (p24);       // pin 6 
+
+DigitalIn row1 (p27);        // pin 3
+DigitalIn row2 (p22);        // pin 8
+DigitalIn row3 (p23);        // pin 7
+DigitalIn row4 (p25);        // pin 5
+
+DigitalOut test1(LED1);
+DigitalOut test2(LED2);
+DigitalOut test3 (LED3); 
+int count;
+void DisplayNumber(int);
+
+
+char keypad(void) 
+{
+    col1 = 1;             //colunm 1 high
+    col2 = 0; 
+    col3 = 0; 
+    
+    if (row1==1)
+    {
+        while(row1==1){}
+        
+        col1 = 0;             
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(1);
+        
+                    
+    }
+    else if (row2==1)           
+    {
+        while (row2==1){}
+        
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(4);           
+    } 
+    else  if (row3==1)         
+    {
+        while (row3==1){}
+        
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(7);
+    }
+    else if (row4==1)
+    {
+        while (row4==1){}
+        
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(11);
+    }
+        
+    return(0);
+}
+    
+char keypad2(void)
+{   
+    col1 = 0;            //colunm 2 high
+    col2 = 1;
+    col3 = 0;
+    
+    if (row1==1)
+    {
+        while(row1==1){}
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(2);
+    }
+    else if (row2==1)
+    {
+        while (row2==1){}
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(5);
+    }
+    else if (row3==1)
+    {
+        while (row3==1){}
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(8);
+    }
+    
+    else if (row4==1)
+    {
+        while (row4==1){}
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(0);
+    }
+return(0);   
+}
+
+char keypad3(void)
+{
+    col1 = 0;                //colunm 3 high
+    col2 = 0;
+    col3 = 1;
+    
+    if (row1==1)
+    {
+        while (row1==1){}
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(3);
+    }
+    else if (row2==1)
+    {
+        while (row2==1){}
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(6);
+    }
+    else if (row3==1)
+    {
+        while (row3==1){}
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(9);
+    }
+    else if (row4==1)
+    {
+        while (row4==1){}
+        col1 = 0;
+        col2 = 0;
+        col3 = 0;
+        DisplayNumber(10);
+    }
+        
+    return(0);
+}
+
+int main()
+{
+   DisplayNumber(0); 
+    while(1)
+    {
+        keypad();
+        keypad2();
+        keypad3();
+    }
+}
+
+void DisplayNumber(int num)
+{
+     switch(num)
+     {
+        case 0:
+            LED_Disp = ~0x3F;
+            break;
+        case 1:
+            LED_Disp = ~0x06;
+            break;
+        case 2:
+            LED_Disp = ~0x5B;
+            break;
+        case 3:
+            LED_Disp = ~0x4F;
+            break;
+        case 4:
+            LED_Disp = ~0x66;
+            break;
+        case 5:
+            LED_Disp = ~0x6D;
+            break;
+        case 6:
+            LED_Disp = ~0x7D;
+            break; 
+        case 7:
+            LED_Disp = ~0x07;
+            break;
+        case 8:
+            LED_Disp = ~0x7F;
+            break;
+        case 9:
+            LED_Disp = ~0x67;
+            break; 
+        case 10: //#
+            LED_Disp = ~0x5c;
+            break;
+        case 11:   //*
+            LED_Disp = ~0x63;
+            break;
+    }
+}
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Feb 12 11:10:52 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file