led test for academic practice

Dependencies:   mbed

Fork of LED_FLASH_TEST_SU by naoto tanaka

Files at this revision

API Documentation at this revision

Comitter:
NT32
Date:
Fri Apr 11 05:14:02 2014 +0000
Parent:
0:68fbb882ee59
Commit message:
update

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 68fbb882ee59 -r d1e024be1615 main.cpp
--- a/main.cpp	Thu Apr 10 12:23:30 2014 +0000
+++ b/main.cpp	Fri Apr 11 05:14:02 2014 +0000
@@ -2,58 +2,42 @@
 
 BusOut leds(P1_13, P1_14, P1_22, P0_17, P0_18, P0_19, P1_15, P0_1);
 
+void single(unsigned char bit);
+void all();
+void rotate();
+
 int main()
 {
-    unsigned char hex = 0x00;
-    int state = 0, count = 0;
+
     while(1)
     {
-        // single led flash
-        while(state == 0)
-        {
-            count++;
-            leds = 1;
-            if(count == 20)
-            {
-                state++;
-            }
-            wait(0.1);
-        }
-        
-        hex = 0xff;
-        count = 0;
-        
-        //all led blink
-        while(state == 1)
-        {
-            count++;
-            //exclusive or.(all bits flipping)
-            leds = hex ^ 0xff;
-            if(count == 6)
-            {
-                state++;
-            }
-            wait(0.5);
-        }
-        
-        hex = 0x01;
-        count = 0;
-        
-        //flashing led rotate
-        while(state == 2)
-        {
-            count++;
-            //bit rotate
-            leds = hex << 1;
-            if(hex == 0)
-            {
-                hex = 0x01;
-            }
-            if(count == 24)
-            {
-                state = 0;
-            }
-            wait(0.125);
-        }
+        single(0);
+        wait(2);
+        all();
+        all();
+        all();
+        rotate();
+        rotate();    
     }
 }
+
+void single(unsigned char bit)
+{
+    leds = 1 << bit;
+}
+void all()
+{
+    leds = 0x0;
+    wait(0.5);
+    leds = 0xff;
+    wait(0.5);
+}
+void rotate()
+{
+    volatile uint8_t i;
+    for(i = 0x00; i < 8; i++)
+    {
+        leds = 1 << i;
+        wait(0.125);
+    }
+}
\ No newline at end of file