working button incrementer

Dependencies:   mbed

Revision:
0:bfc9617c596c
Child:
1:ac916e153bc4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 10 15:31:26 2021 +0000
@@ -0,0 +1,81 @@
+#include "mbed.h"
+ 
+DigitalIn button_up(p14);
+DigitalIn button_down(p15);
+
+BusOut LED_Disp(p7,p11,p9,p8,p5,p6,p10,p12);
+
+void DisplayNumber(int);
+
+int main()
+{
+    int counter = 0;
+    
+    while(1)
+    {
+        if (counter>9) counter = 0;
+        
+        if (counter<0) counter = 0;
+        
+        DisplayNumber(counter);
+        
+        if (button_up == 1)
+        {
+            counter++;
+            
+            wait(0.2);
+            
+            while(button_up==1)
+            {}
+        }
+        
+        if (button_down == 1)
+        {
+            counter--;
+            
+            wait(0.2);
+            
+            while(button_down==1)
+            {}
+        }
+    }
+}
+
+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; 
+    }
+}
+             
+        
\ No newline at end of file