This program is for "LEDCUBE4mbed". You can change the mode for changing the value of "debug".

Dependencies:   ConfigFile FatFileSystem SDFileSystem mbed

Revision:
3:b98db4a46561
Parent:
2:96833c69287d
--- a/main.cpp	Fri Aug 10 03:50:29 2012 +0000
+++ b/main.cpp	Sun Nov 04 08:57:57 2012 +0000
@@ -22,6 +22,10 @@
  */
  
 BusOut leds(LED1, LED2, LED3, LED4);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
 DigitalOut C1(p25); //line1 to line5
 DigitalOut C2(p24); //line6 to line10
 DigitalOut C3(p23); //line11 to line15
@@ -34,7 +38,7 @@
 DigitalIn resets(p19);
 DigitalIn replay(p18);
 DigitalIn start(p17);
-
+Ticker timer;
 
 /* ==================================================
  * Not implemented
@@ -51,23 +55,57 @@
 SDFileSystem  sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS,  "sd");  //  mosi, miso, sclk, cs, name  (HW modification candidate)
 */
 
+/* ==================================================
+ * Debug mode switch
+ * ==================================================
+ * if(debug == 1)
+ * {
+ *     printf("");
+ * }
+ * if(debug == 0)
+ * {
+ *     //printf("");
+ * }
+ */
+int debug = 0;
+
+void time() {
+    led1 = 1;
+    wait_ms(50);
+    led1 = 0;
+    wait_ms(50);
+}
+
 int main() {
+    start:
+    if(debug == 1){
+        printf("LoadingProgram...\n");
+        printf("Loaded.\n");
+    }
     while(1){
         if(start == 1){
+            if(debug == 1){
+                printf("Start!\n");
+            }
             goto replay;
         } else {
-            leds = 8;
-            wait_ms(50);
-            leds = 0;
-            wait_ms(50);
+            //timer.attach(&time, 0.05);
+            led4 = 1;
+            wait(volume);
+            led4 = 0;
+            wait(volume);
         }//else
     }//while
     replay:
     float speed = volume;
-    printf("This program will Set Pattern in %f sec.\n",speed);
+    if(debug == 1){
+        printf("This program will Set Pattern in %f sec.\n",speed);
+    }
     //error
     if (!cfg.read("/local/pattern.cfg")) {
-        printf("Failure to read a configuration file.\n");
+        if(debug == 1){
+            printf("Failure to read a configuration file.\n");
+        }
         while(1){
             leds = 15;
             wait(0.1);
@@ -77,7 +115,9 @@
     }
     
     //read file
-    printf("reading file...\n");
+    if(debug == 1){
+        printf("reading file...\n");
+    }
     cfg.read("/local/pattern.cfg");
     
     const int cnt = cfg.getCount();
@@ -91,19 +131,27 @@
         if (cfg.getKeyAndValue(i, buf_key, sizeof(buf_key), buf_value, sizeof(buf_value))) {
             
             sin2 = strtol(buf_value, NULL, 2);
-            printf("%d = %d\n", i+1, sin2);
+            if(debug == 1){
+                printf("%d = %d\n", i+1, sin2);
+            }
             
             //SetPattern
-            printf("SetPattern\n");
+            if(debug == 1){
+                printf("SetPattern\n");
+            }
             if((i+1) % 5 == 0){
-                printf("(i+1) % 5 == 0\n");
+                if(debug == 1){
+                    printf("(i+1) % 5 == 0\n");
+                }
             } else {
                 C5 = sin2 & 0x1;
                 C4 = (sin2 >> 1) & 0x1;
                 C3 = (sin2 >> 2) & 0x1;
                 C2 = (sin2 >> 3) & 0x1;
                 C1 = (sin2 >> 4) & 0x1;
-                printf("C1:%d,C2:%d,C3:%d,C4:%d,C5:%d\n",(sin2 >> 4) & 0x1,(sin2 >> 3) & 0x1,(sin2 >> 2) & 0x1,(sin2 >> 1) & 0x1,sin2 & 0x1);
+                if(debug == 1){
+                    printf("C1:%d,C2:%d,C3:%d,C4:%d,C5:%d\n",(sin2 >> 4) & 0x1,(sin2 >> 3) & 0x1,(sin2 >> 2) & 0x1,(sin2 >> 1) & 0x1,sin2 & 0x1);
+                }
                 sclock = 1;
                 leds = i+1;
                 wait_ms(50);
@@ -113,18 +161,27 @@
                     mclock = 1;
                     leds = 15;
                     wait(volume);
-                    printf("Switch to Next Pattern\n");
+                    if(debug == 1){
+                        printf("Switch to Next Pattern\n");
+                    }
                 }
                 sclock = 0;
                 mclock = 0;
             }
         } else {
-            printf("No.%3d:Failure to get a configuration.\n", i);
+            if(debug == 1){
+                printf("No.%3d:Failure to get a configuration.\n", i);
+            }
         }//else
     }//for
+    if(debug == 1){
+        printf("Done.\n");
+    }
     while(1){
         if(resets == 1){
-            printf("Reset!\n");
+            if(debug == 1){
+                printf("Reset!\n");
+            }
             C1 = 0;
             C2 = 0;
             C3 = 0;
@@ -140,9 +197,14 @@
                 wait_ms(10);
                 mclock = 0;
             }//for
+        goto start;
         }//if
         if(replay == 1){
+            if(debug == 1){
+                printf("Restart!\n");
+            }
             goto replay;
         }
     }//while
+    goto start;
 }//main
\ No newline at end of file