iModela(iM-01) de sakusei sita PCB no kitchenTimer wo clock ni henko sita monodesu.

Dependencies:   SevenSegLed SwDigital mbed Sound

Files at this revision

API Documentation at this revision

Comitter:
suupen
Date:
Sun Apr 22 11:30:33 2012 +0000
Parent:
0:b7cdbc649bd3
Commit message:
V2.0 120422 : melody to chime no kaizen. hyoji no kaizen

Changed in this revision

SevenSegLed.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b7cdbc649bd3 -r fe97b047f96b SevenSegLed.lib
--- a/SevenSegLed.lib	Sun Apr 08 03:36:28 2012 +0000
+++ b/SevenSegLed.lib	Sun Apr 22 11:30:33 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/suupen/code/SevenSegLed/#cca0fd8ccb97
+http://mbed.org/users/suupen/code/SevenSegLed/#f4680c84b347
diff -r b7cdbc649bd3 -r fe97b047f96b main.cpp
--- a/main.cpp	Sun Apr 08 03:36:28 2012 +0000
+++ b/main.cpp	Sun Apr 22 11:30:33 2012 +0000
@@ -5,6 +5,7 @@
 // 24h display clock
 //
 // V1.0 120402
+// V2.0 120422 : melody and chime no henko. hyoji no kaizen
 // 
 // <schematic>
 // 1.seven segment numeric LED Display : OSL40562-LR
@@ -69,11 +70,6 @@
 #include "Sound.h"
 #include "SwDigital.h"
 
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-
 Ticker timeout100ms;     // 100ms interrupt
 
 Sound sound(p21, p22);
@@ -87,11 +83,10 @@
     aSw
 };
 
-//SevenSegLed sevenSegLed(1, 1, p19, p7, p10, p12, p13, p20, p9, p11, p18, p5, p6, p8);   // OSL40562-LR(schematic bug)
 SevenSegLed sevenSegLed(1, 0, p19, p5, p10, p12, p13, p18, p9, p11, p20, p7, p6, p8);   // OSL40562-LR(seikiban)
 
 uint8_t D_7seg[4] = {0, 0, 0, 0};
-uint8_t D_dot[4] = {0, 1, 0, 0};
+uint8_t D_dot[4]  = {0, 1, 0, 0};
 
 uint8_t C_flicker; // timer setti ji no henko keta flicker kyoka (100[ms]/count) 0:flicker request ohter:kinsi
 #define Z_flicker (5 * 10)
@@ -101,12 +96,10 @@
 
 enum timer_t{
     stop,
-    set1min,
-    set10min,
+    setMin,
+    setHore,
     count,
-    chime,
-    timeup
-};
+ };
 timer_t M_timer = stop;
 
 uint8_t F_flip100ms;    // 100ms keika goto ni 0 or 1 
@@ -114,22 +107,50 @@
 
 time_t seconds;
 struct tm  *A_time;   // genzai jikoku
-#define Z_japanOffset   (9 * 60 * 60)   // japan time offset (utc + 9h)
 
-
+//===================================
+// beep (sw sosa ji no oto)
+//===================================
 void beep(void){
 // tone1 
     Sound::sound_t oto = {1,0x95,200,100};
     sound.sound_sound(oto);
 }
 
-void beep2(void){
-// tone1 
-    Sound::sound_t oto = {1,0xA4,1200,1000};
-    sound.sound_sound(oto);
+//**********************************************************
+// chime
+//**********************************************************
+uint8_t C_chime;    // chime kaisuu 1 - 255 (1/1[kai]/count)
+
+//=====================================================
+// chime request
+//      no : chime no kaisuu 1 - 255 ( 1/1 [kai]/count)
+//=====================================================
+void chimeSet(uint8_t no){
+    C_chime = no;
 }
 
+//====================================
+// chime check and output
+//    10 - 100 ms syuuki de call suru
+//====================================
+void chimeCheck(void){
+    if(C_chime > 0){
+        if((sound.sound_sound() == false) && (sound.sound_enso() == false)) {
+            Sound::sound_t oto = {1,0xF4,2500,1500};
+            sound.sound_sound(oto);
+            C_chime--;
+        }
+    }
+}
+
+//***************************************************
+// melody data tabel
+//***************************************************
+
+//================================
 // "westminster chime" merody data
+//================================
     const Sound::sound_t WESTMINSTER[] =     {
     //  onkai,hatuon jikan[ms]
         {1,0xA4,1200,1000},
@@ -154,7 +175,10 @@
                
         {1,0xFF,1000,0},    // end
     };
+
+//==========================
 // "ramen chime" merody data
+//==========================
     const Sound::sound_t RAMEN[] =     {
     //  onkai,hatuon jikan[ms]
         {1,0xC5,300,500},
@@ -174,7 +198,9 @@
         {1,0xFF,1000,500},    // end
     };
 
+//=============================
 // "demekin no uta" merody data
+//=============================
     const Sound::sound_t DEMEKIN[] =     {
     //  onkai,hatuon jikan[ms]
         {1,0xC5,600,500},     // de
@@ -220,27 +246,6 @@
 };
 
 //=============================
-// clock 
-//=============================
-/*
-    time_t ctTime;
-    struct tm *jst_time;
-    
-    _JIKOKU wk = *j;
-
-
-    ctTime = time(NULL);
-    ctTime += 32400;
-    jst_time = localtime(&ctTime);
-
-    
-    wk.sec  = jst_time->tm_sec;
-    wk.min  = jst_time->tm_min;
-    wk.hour = jst_time->tm_hour;
-*/    
-
-
-//=============================
 // timer SW seni
 //=============================
 void timerSeni(void){
@@ -248,15 +253,15 @@
 
     // aSw(settei SW)
     if(sw.checkEdgeOn(aSw) == 1){
-        if((M_timer != set1min) && (M_timer != set10min)){
+        if((M_timer != setMin) && (M_timer != setHore)){
             beep();
-            M_timer = set1min;
+            M_timer = setMin;
             
             // genzai jikoku kakuno
             seconds = time(NULL);
             A_time = localtime(&seconds);
         }
-        else if((M_timer == set1min) || (M_timer == set10min)){
+        else if((M_timer == setMin) || (M_timer == setHore)){
             beep();
             M_timer = count;
             
@@ -278,14 +283,14 @@
 
     switch(M_timer){
     case stop:
-        // other aSw,bSw then set1min
+        // other aSw,bSw then setMin
         if((sw.checkEdgeOn(upSw) == 1)
          ||(sw.checkEdgeOn(downSw) == 1)
          ||(sw.checkEdgeOn(leftSw) == 1)
          ||(sw.checkEdgeOn(rightSw) == 1)
          ){
             beep();
-            M_timer = set1min;
+            M_timer = setMin;
             C_flicker = 0;
             
             // genzai jikoku kakuno
@@ -293,17 +298,17 @@
             A_time = localtime(&seconds);
         }
         break;
-    case set1min:
+    case setMin:
         if(sw.checkEdgeOn(leftSw) == 1){
             beep();
-            M_timer = set10min;
+            M_timer = setHore;
             C_flicker = 0;
         }
         break;
-    case set10min:
+    case setHore:
         if(sw.checkEdgeOn(rightSw) == 1){
             beep();
-            M_timer = set1min;
+            M_timer = setMin;
             C_flicker = 0;
         }
         break;
@@ -313,75 +318,57 @@
         
         // 59 kara 0 byo ni nattara melody wo narasu
         if((B_timesec == 59) && (A_time->tm_sec == 0)){
-        
+            // jikoku chime no kaisuu set
+            uint8_t C_chime = A_time->tm_hour;
+            if(C_chime == 0){
+                C_chime = 12;
+            }
+            else if(C_chime > 12){
+                C_chime -= 12;
+            }
+
+            // jikoku no melody and chime
             if(A_time->tm_min == 0){
                 if(A_time->tm_hour == 12){
                     sound.sound_enso((Sound::sound_t*)RAMEN);
                     sound.sound_enso(true);
+                    chimeSet(C_chime);
                 }
                 else {
                     sound.sound_enso((Sound::sound_t*)WESTMINSTER);
                     sound.sound_enso(true);
+                    chimeSet(C_chime);
                 }
             }
-                           
+            
+            // 30min no chime               
             if(A_time->tm_min == 30){
-                sound.sound_enso((Sound::sound_t*)DEMEKIN);
-                sound.sound_enso(true);
+                chimeSet(2);
             }
-         
+            
+            // 15min or 45min no chime
             if((A_time->tm_min == 15) || (A_time->tm_min == 45)){
-                beep2();
+                chimeSet(1);
             }
          }
-        B_timesec = A_time->tm_sec;
+        B_timesec = A_time->tm_sec; // jikai hikaku yo time data kioku
       break;
     
-    case chime: // 120115 bug fix
-/*
-        if(D_timerSec == (3 * 60)){
-            sound.sound_enso((Sound::sound_t*)RAMEN);
-        }
-        else if(D_timerSec < (60 * 60)){
-            sound.sound_enso((Sound::sound_t*)WESTMINSTER);
-        }
-        else{
-            sound.sound_enso((Sound::sound_t*)DEMEKIN);
-        }
-            
-        sound.sound_enso(true);
-        M_timer = timeup;
-*/        
-        break;
-/*    
-    case timeup:
-        // other aSw,bSw then set1min
-        if((sw.checkEdgeOn(upSw) == 1)
-         ||(sw.checkEdgeOn(downSw) == 1)
-         ||(sw.checkEdgeOn(leftSw) == 1)
-         ||(sw.checkEdgeOn(rightSw) == 1)
-         ){
-            beep();
-            M_timer = set1min;
-            C_flicker = 0;
-        }    
-        break;
- */ 
-    default:
+     default:
+        // nothing
         break;
     }
 
 }
 //============================
-// timer set
+// time set
 //============================
 void timerSet(void){
-//    int16_t work;
 
     switch(M_timer){
     case stop:
         break;
-    case set1min:
+    case setMin:
         if(sw.checkEdgeOn(upSw) == 1){
             beep();
             if(A_time->tm_min < 59){
@@ -404,7 +391,7 @@
             C_flicker = Z_flicker;
         }
         break;
-    case set10min:
+    case setHore:
         if(sw.checkEdgeOn(upSw) == 1){
             beep();
             if(A_time->tm_hour < 23){
@@ -428,12 +415,10 @@
         }
         break;
     case count:
-        break;
-    case chime:
-        break;
-    case timeup:
+        // nothing
         break;
     default:
+        // nothing
         break;
     }
     
@@ -460,8 +445,9 @@
         D_dot[3] = 0;
         
         break;
-    case set1min:
-    case set10min:
+    case setMin:    // setHore to onaji
+    case setHore:
+        sevenSegLed.smoothSet(1);   // hyoji hard
         D_7seg[0] = A_time->tm_hour / 10;
         D_7seg[1] = A_time->tm_hour % 10;
         D_7seg[2] = A_time->tm_min / 10;
@@ -469,7 +455,7 @@
 
         // settei basyo no tenmetu        
         if((C_flicker == 0) && (F_flip500ms == 0)){
-            if(M_timer == set1min){
+            if(M_timer == setMin){
                 D_7seg[2] = 0x10;
                 D_7seg[3] = 0x10;
             }
@@ -486,6 +472,7 @@
 
         break;
     case count:
+        sevenSegLed.smoothSet(0);   // hyoji smooth
         seconds = time(NULL);
         A_time = localtime(&seconds);
         
@@ -493,64 +480,30 @@
         D_7seg[1] = A_time->tm_hour % 10;
         D_7seg[2] = A_time->tm_min / 10;
         D_7seg[3] = A_time->tm_min % 10;
-/*
-        D_7seg[0] = A_time->tm_min / 10;
-        D_7seg[1] = A_time->tm_min % 10;
-        D_7seg[2] = A_time->tm_sec / 10;
-        D_7seg[3] = A_time->tm_sec % 10;
- */
+
         D_dot[0] = 0;
         D_dot[1] = 1;
         D_dot[2] = 0;
-   
+
+        // byo no dot no tenmetu   
         if((A_time->tm_sec % 2) == 0){
             D_dot[3] = 0;
         }
         else{
             D_dot[3] = 1;
         }
-
         break;
-    case chime: // same "timeup"
-
-#ifdef debug
-    D_7seg[0] = 0x0E;
-    D_7seg[1] = 0x10;
-    D_7seg[2] = 0x10;
-    D_7seg[3] = 0x10;
-    break;
-#endif //debug
 
-    case timeup:
-        if(F_flip500ms == 1){
-            D_7seg[0] = 0x0f;
-            D_7seg[1] = 0x0f;
-            D_7seg[2] = 0x0f;
-            D_7seg[3] = 0x0f;
-        }
-        else{
-            D_7seg[0] = 0x10;
-            D_7seg[1] = 0x10;
-            D_7seg[2] = 0x10;
-            D_7seg[3] = 0x10;
-        }
-        
-        D_dot[0] = 0;
-        D_dot[1] = 0;
-        D_dot[2] = 0;
-        D_dot[3] = 0;
-        break;
     default:
         break;
     }
-    sevenSegLed.SevenSegLed_main(D_7seg, D_dot);
+    sevenSegLed.SevenSegLed_main(D_7seg, D_dot);    // 7segment hyoji
 }
 
 //================================
 // 100ms interrupt
 //================================
 void interrupt100ms(void){
-//    led2 = !led2;
     static uint8_t C_100ms = 0;
     
     C_100ms++;
@@ -587,18 +540,6 @@
         timerSeni();
         timerSet();
         sevenSegDisplay();
-/*
-        // debug code
-        if((sw.checkEdgeOn(leftSw) == 1)
-         ||(sw.checkEdgeOn(rightSw) == 1)
-         ||(sw.checkEdgeOn(upSw) == 1)
-         ||(sw.checkEdgeOn(downSw) == 1)
-         ||(sw.checkEdgeOn(aSw) == 1)
-         ||(sw.checkEdgeOn(bSw) == 1)
-        ){
-            led1 = !led1;
-        }
- */       
- 
+        chimeCheck();
     }
 }