dot Matrix Led Clock with TLC5940

Dependencies:   Kc_TLC5940 mbed

Revision:
2:6edd801ae662
Parent:
1:7afb65e75dcd
Child:
3:25540a08a8d8
--- a/main.cpp	Tue Jul 28 00:33:47 2015 +0000
+++ b/main.cpp	Tue Jul 28 01:53:27 2015 +0000
@@ -22,8 +22,18 @@
 DigitalIn slowSw = dp25;
 
 #define dispTime 10
-#define fastCount 1024
+#define fastCount 500
 #define slowCount 50
+#define brightChange 1
+#define brightMax 2024
+
+int brightCangeValue;
+
+Ticker secTick;
+
+int min;//
+int hour =1;//
+unsigned short LEDS[16];
 
 //時間の数字をドッドの数字に変換
 unsigned char hourDecfont( int num , int colm )
@@ -80,51 +90,89 @@
     mask = mask << 1;
     col8 = ( temp & mask );
 }
+
+void minUp()
+{
+    for( int bright = brightMax ; bright > 0; bright-=brightCangeValue )
+    { 
+        for( int colmn=0 ; colmn<16 ; colmn++ )
+        {
+            brightCangeValue = brightChange;
+            if( fastSw == 1 )
+                brightCangeValue = fastCount;
+            if( slowSw == 1 )
+                brightCangeValue = slowCount;
+                
+            for( int h=0; h<16 ; h++ )
+                LEDS[h] = 0;
+            LEDS[colmn] = (unsigned short)bright;
+            offDisp(blank, gsclk);
+            if( colmn<8 )
+                fontOut( decfont( min , colmn ) );
+            else
+                fontOut( hourDecfont( hour , colmn-8 ) );
+            update_led (driver, xlat, blank, gsclk , LEDS);
+            wait_us(dispTime);
+        }
+    }
+    
+    //1分増加させる 60になったら1時間増やす 12時間を超えたら1時に戻す
+    min += 1;
+    if( min >= 60 )
+    {
+        min = 0;
+        hour++;
+        if( hour > 12 )
+            hour = 1;
+    }
+    
+    for( int bright = 0 ; bright < brightMax; bright+=brightCangeValue )
+    {
+        for( int colmn=0 ; colmn<16 ; colmn++ )
+        {
+            //PWMをクリア
+            for( int h=0; h<16 ; h++ )
+                LEDS[h] = 0;
+            LEDS[colmn] = (unsigned short)bright;    //必要なピンのみ指定した明るさでON
+            offDisp(blank, gsclk);          //PWM強制OFF
+            if( colmn<8 )
+                fontOut( decfont( min , colmn ) );
+            else
+                fontOut( hourDecfont( hour , colmn-8 ) );
+            update_led (driver, xlat, blank, gsclk , LEDS);
+            wait_us(dispTime);
+        }
+    }
+
+}
+
+
+
 int main() {
-    
     initFont();
     
     setup (driver, vprg, xlat, blank, gsclk, num_ics );
+    brightCangeValue = brightChange;
+    secTick.attach(&minUp, 60.0);
     
-    unsigned short LEDS[16];
     while(1)
     {
-        for( int hour =1 ; hour<13 ; hour++ )
-            {
-            for( int min=0 ; min<60 ; min++)
+/*        for( hour =1 ; hour<13 ; hour++ )
+        {
+            for( min = 1 ; min<60 ; min )
             {
-                for( int bright = 0 ; bright < 1024; bright+=2 )
-                {
+                while(1)
+                {*/
                     if( fastSw == 1 )
-                        bright+=fastCount;
+                        minUp();
                     if( slowSw == 1 )
-                        bright+=slowCount;
+                        minUp();
                     for( int colmn=0 ; colmn<16 ; colmn++ )
                     {
-                        //PWMをクリア
+                            
                         for( int h=0; h<16 ; h++ )
                             LEDS[h] = 0;
-                        LEDS[colmn] = (unsigned short)bright;    //必要なピンのみ指定した明るさでON
-                        offDisp(blank, gsclk);          //PWM強制OFF
-                        if( colmn<8 )
-                            fontOut( decfont( min , colmn ) );
-                        else
-                            fontOut( hourDecfont( hour , colmn-8 ) );
-                        update_led (driver, xlat, blank, gsclk , LEDS);
-                        wait_us(dispTime);
-                    }
-                }
-                for( int bright = 1024 ; bright > 0; bright-=2 )
-                { 
-                    if( fastSw == 1 )
-                        bright-= fastCount;
-                    if( slowSw == 1 )
-                        bright-=slowCount;
-                    for( int colmn=0 ; colmn<16 ; colmn++ )
-                    {
-                        for( int h=0; h<16 ; h++ )
-                            LEDS[h] = 0;
-                        LEDS[colmn] = (unsigned short)bright;
+                        LEDS[colmn] = (unsigned short)brightMax;
                         offDisp(blank, gsclk);
                         if( colmn<8 )
                             fontOut( decfont( min , colmn ) );
@@ -133,10 +181,10 @@
                         update_led (driver, xlat, blank, gsclk , LEDS);
                         wait_us(dispTime);
                     }
-                }
+     /*           }
             }
 
 
-        }
+        }*/
     }
 }