TaChing Yu / Mbed 2 deprecated 4_7SgementLED_74HC595

Dependencies:   mbed

Revision:
0:b7855d83d15b
Child:
1:5002e9577641
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Sep 04 02:34:07 2016 +0000
@@ -0,0 +1,119 @@
+#include "mbed.h"
+
+DigitalOut datapin(D8);    
+DigitalOut latchpin(D9);   
+DigitalOut clockpin(D10);
+DigitalOut ww(D11);
+DigitalOut xx(D12);
+DigitalOut yy(D13);
+DigitalOut zz(D14);
+
+const int state[10][7]= {
+  { 0, 1, 1, 1, 1, 1, 1}, // 0
+  { 0, 0, 0, 0, 1, 1, 0}, // 1
+  { 1, 0, 1, 1, 0, 1, 1}, // 2
+  { 1, 0, 0, 1, 1, 1, 1}, // 3
+  { 1, 1, 0, 0, 1, 1, 0}, // 4
+  { 1, 1, 0, 1, 1, 0, 1}, // 5
+  { 1, 1, 1, 1, 1, 0, 0}, // 6
+  { 0, 0, 0, 0, 1, 1, 1}, // 7
+  { 1, 1, 1, 1, 1, 1, 1}, // 8
+  { 1, 1, 0, 0, 1, 1, 1}  // 9
+};
+void seg1(int num)
+{
+    ww=1;
+    xx=1;
+    yy=1;
+    zz=1;
+    latchpin=0;
+    for(int i=0;i<=7;i++)
+    {
+        datapin=state[num][i];
+        clockpin=1;
+        clockpin=0;
+    }
+    latchpin=1;
+    ww=0;
+}
+void seg2(int num)
+{
+    ww=1;
+    xx=1;
+    yy=1;
+    zz=1;
+    latchpin=0;
+    for(int i=0;i<=7;i++)
+    {
+        datapin=state[num][i];
+        clockpin=1;
+        clockpin=0;
+    }
+    latchpin=1;
+    xx=0;
+}
+void seg3(int num)
+{
+    ww=1;
+    xx=1;
+    yy=1;
+    zz=1;
+    latchpin=0;
+    for(int i=0;i<=7;i++)
+    {
+        datapin=state[num][i];
+        clockpin=1;
+        clockpin=0;
+    }
+    latchpin=1;
+    yy=0;
+}
+void seg4(int num)
+{
+    ww=1;
+    xx=1;
+    yy=1;
+    zz=1;
+    latchpin=0;
+    for(int i=0;i<=7;i++)
+    {
+        datapin=state[num][i];
+        clockpin=1;
+        clockpin=0;
+    }
+    latchpin=1;
+    zz=0;
+}
+int main() 
+{
+    int round=0,round2=0,round3=0,round4=0;
+    while(1) 
+    {   
+        seg1(round);
+        round++;
+        wait_ms(5);
+        seg2(round2);
+        wait_ms(5);
+        seg3(round3);
+        wait_ms(5);
+        seg4(round4);
+        wait_ms(5);
+        if(round == 10)
+        {
+            round=0;round2++;
+            if(round2 == 10)
+            {
+                round2=0;round3++;
+                if(round3 == 10)
+                {
+                    round3=0;
+                    round4++;
+                    if(round4 == 10)
+                    {
+                        round4=0;
+                    }
+                }
+            }
+        }
+    }
+}