Stopwatch library with start, stop, and getTime functions. Returns a 00:00:00 in MM:SS:MS format with a max duration of ~30min per documentation on the Timer class. Can easily be output through an LCD/TFT with printf(stopwatch.getTime());

Fork of Stopwatch by Matt Dominey

Files at this revision

API Documentation at this revision

Comitter:
fox46
Date:
Wed May 08 09:16:46 2013 +0000
Parent:
1:bb9b4593a013
Commit message:
added gettimeFshort, shorter formated "0:00:0"

Changed in this revision

Stopwatch.cpp Show annotated file Show diff for this revision Revisions of this file
Stopwatch.h Show annotated file Show diff for this revision Revisions of this file
diff -r bb9b4593a013 -r 2202f5336acb Stopwatch.cpp
--- a/Stopwatch.cpp	Wed Apr 24 16:46:10 2013 +0000
+++ b/Stopwatch.cpp	Wed May 08 09:16:46 2013 +0000
@@ -19,6 +19,11 @@
     sw.stop();
 }
 
+void Stopwatch::reset() {
+    // Reset the timer
+    sw.reset();
+}
+
 char* Stopwatch::getTime() {
     // Convert time in milliseconds to 00:00:00 format for output to LCD
     // Returns a pointer to a 8 char array in time format
@@ -28,6 +33,19 @@
     min = (sec/60);
     sec = sec - (min*60);
     ms = (ms/10);
-    sprintf(buffer, "%02d:%02d:%02d", min, sec, ms);
-    return buffer;
+    sprintf(buffer1, "%02d:%02d:%02d", min, sec, ms);
+    return buffer1;
+}
+
+char* Stopwatch::getTimeFshort() {
+    // Convert time in milliseconds to 0:00:0 format for output to LCD
+    // Returns a pointer to a 6 char array in time format
+    ms1 = sw.read_ms();
+    sec = (ms1/1000);
+    ms1 = ms1 - (sec*1000);
+    min = (sec/60);
+    sec = sec - (min*60);
+    ms1 = (ms1/100);
+    sprintf(buffer2,"%1d:%02d:%1d", min, sec, ms1);
+    return buffer2;
 }
\ No newline at end of file
diff -r bb9b4593a013 -r 2202f5336acb Stopwatch.h
--- a/Stopwatch.h	Wed Apr 24 16:46:10 2013 +0000
+++ b/Stopwatch.h	Wed May 08 09:16:46 2013 +0000
@@ -9,12 +9,18 @@
     ~Stopwatch();
     void start();
     void stop();
+    void reset();
     char* getTime();
+    char* getTimeFshort();
     void countDown(int startTime);
 private:
     int ms;
+    int ms1;
     int sec;
     int min;
-    char buffer[9];
+   // int sec1;
+   // int min1;
+    char buffer1[9];
+    char buffer2[7];
     Timer sw;
 };
\ No newline at end of file