timer

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
okazbb
Date:
Fri Jan 08 02:35:47 2016 +0000
Parent:
0:2a4b25dd671a
Commit message:
LED??

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Dec 26 02:58:58 2015 +0000
+++ b/main.cpp	Fri Jan 08 02:35:47 2016 +0000
@@ -8,8 +8,8 @@
 DigitalIn goalSW(PB_9);
 
 //setting
-const int DRAW_DELAY    = 230;
-const int SWITCH_DELAY  = 3000;
+const int DRAW_DELAY    = 235;
+const int SWITCH_DELAY  = 2000;
 const int LED_DELAY     = 1500;
 
 //local
@@ -19,6 +19,7 @@
 int goal_time   = 0;
 int led_time    = 0;
 bool running    = false;
+Timer system_timer;
 Timer timer; //https://developer.mbed.org/users/okini3939/notebook/timer_jp/
 //time https://developer.mbed.org/users/okini3939/notebook/time_jp/
 
@@ -31,23 +32,23 @@
     int time_sec = sec % 60;
     int time_ms  = ms % 1000;
     
+    
     //TODO 0.004秒遅延する
-    timerLed.printf("%1d.", time_min);
-    wait(0.001);
-    
-    timerLed.printf("%2d.", time_sec);
-    wait(0.001);
-    
-    timerLed.printf("%3d", time_ms);
-    wait(0.001);
-    
+
+    char s[9];
+    sprintf(s, "%01d.%02d.%03d-%1d", time_min, time_sec, time_ms, running);
+    string str(s);
+    for(int i = 0; i < (int)str.size(); ++i){
+        char ch = str[i];
+        timerLed.putc(str[i]);
+        wait(0.01);
+    }
     if(running){
-        timerLed.printf("-1");
+        timerLed.putc('1');
     } else {
-        timerLed.printf("-0");
+        timerLed.putc('0');
     }
-    wait(0.001);
-    
+    wait(0.01);
     timerLed.printf("\r");
 }
 
@@ -76,17 +77,19 @@
 int main() {
 
   int i = 0;
+  system_timer.start();
   
   wait(1);
-  timerLed.format(8, Serial::None, 1);
+    timerLed.format(8, Serial::None, 1);
     drawLED(0);      
     
   while(1) {       
-    system_time = time(NULL);
+    system_time = system_timer.read_ms();
     
     //start or goal
-    if(startSW == 0){
+    if(goalSW == 1){
         if(start_time + SWITCH_DELAY <= system_time){
+            start_time = system_time;
             if(running){
                 goal();
             } else {
@@ -103,7 +106,7 @@
     }
   
     //led signal
-    if(led_time + 1500 <= LED_DELAY){
+    if(led_time + LED_DELAY <= system_time){
         led_time = system_time;
         led = !led;
         i++;