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

Dependencies:   ConfigFile FatFileSystem SDFileSystem mbed

Revision:
2:96833c69287d
Parent:
1:0991aefbe7be
Child:
3:b98db4a46561
--- a/main.cpp	Thu Aug 09 09:01:48 2012 +0000
+++ b/main.cpp	Fri Aug 10 03:50:29 2012 +0000
@@ -27,16 +27,19 @@
 DigitalOut C3(p23); //line11 to line15
 DigitalOut C4(p22); //line16 to line20
 DigitalOut C5(p21); //line21 to line25
-DigitalOut Call[] = {p25, p24, p23, p22, p21};
+//DigitalOut Call[] = {p25, p24, p23, p22, p21};
 DigitalOut mclock(p5); //mainclock
 DigitalOut sclock(p6); //subclock
+AnalogIn volume(p20);
+DigitalIn resets(p19);
+DigitalIn replay(p18);
+DigitalIn start(p17);
+
 
 /* ==================================================
  * Not implemented
  * ==================================================
- */
-//AnalogIn volume(p20);
-/*
+
 // MicroSD Ssytem
 #include "SDFileSystem.h"
 #define     SD_MOSI     p5
@@ -44,16 +47,24 @@
 #define     SD_SCLK     p7
 #define     SD_CS       p8
  
-//SDFileSystem    sd(p5, p6, p7, p13, "sd");  //  mosi, miso, sclk, cs, name
+//SDFileSystem    sd(p11, p12, p13, p9, "sd");  //  mosi, miso, sclk, cs, name
 SDFileSystem  sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS,  "sd");  //  mosi, miso, sclk, cs, name  (HW modification candidate)
 */
 
-void resetColumn() {
-
-}
-
 int main() {
-
+    while(1){
+        if(start == 1){
+            goto replay;
+        } else {
+            leds = 8;
+            wait_ms(50);
+            leds = 0;
+            wait_ms(50);
+        }//else
+    }//while
+    replay:
+    float speed = volume;
+    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");
@@ -78,24 +89,60 @@
     for (int i = 0; i < cnt; i++) {
         leds = 0;
         if (cfg.getKeyAndValue(i, buf_key, sizeof(buf_key), buf_value, sizeof(buf_value))) {
-            //printf("No.%3d:'%s'='%s'\n", i, buf_key, buf_value);
             
             sin2 = strtol(buf_value, NULL, 2);
             printf("%d = %d\n", i+1, sin2);
             
-            C5 = sin2 & 0x1;
-            C4 = (sin2 >> 1) & 0x1;
-            C3 = (sin2 >> 2) & 0x1;
-            C2 = (sin2 >> 3) & 0x1;
-            C1 = (sin2 >> 4) & 0x1;
-            
-            leds = 1;
-            wait(0.1);
-            leds = 0;
-            wait(0.4);
-            
+            //SetPattern
+            printf("SetPattern\n");
+            if((i+1) % 5 == 0){
+                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);
+                sclock = 1;
+                leds = i+1;
+                wait_ms(50);
+                leds = 0;
+                //Switch to Next Pattern
+                if((i+1) % 5 == 4){
+                    mclock = 1;
+                    leds = 15;
+                    wait(volume);
+                    printf("Switch to Next Pattern\n");
+                }
+                sclock = 0;
+                mclock = 0;
+            }
         } else {
             printf("No.%3d:Failure to get a configuration.\n", i);
+        }//else
+    }//for
+    while(1){
+        if(resets == 1){
+            printf("Reset!\n");
+            C1 = 0;
+            C2 = 0;
+            C3 = 0;
+            C4 = 0;
+            C5 = 0;
+            for(int i = 0; i < 5; i++){
+                sclock = 1;
+                wait_ms(10);
+                sclock = 0;
+            }//for
+            for(int i = 0; i < 5; i++){
+                mclock = 1;
+                wait_ms(10);
+                mclock = 0;
+            }//for
+        }//if
+        if(replay == 1){
+            goto replay;
         }
-    }
-}
\ No newline at end of file
+    }//while
+}//main
\ No newline at end of file