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());

Dependents:   ProgrammaBasis

Files at this revision

API Documentation at this revision

Comitter:
mdomino
Date:
Mon Jul 16 19:46:34 2012 +0000
Commit message:
Stopwatch library

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 000000000000 -r 3328857bf625 Stopwatch.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stopwatch.cpp	Mon Jul 16 19:46:34 2012 +0000
@@ -0,0 +1,33 @@
+#include "Stopwatch.h"
+#include "mbed.h"
+
+Stopwatch::Stopwatch() {
+    // constructor
+}
+
+Stopwatch::~Stopwatch() {
+    // destructor
+}
+
+void Stopwatch::start() {
+    // Start the timer
+    sw.start();
+}
+
+void Stopwatch::stop() {
+    // Stop the timer
+    sw.stop();
+}
+
+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
+    ms = sw.read_ms();
+    sec = (ms/1000);
+    ms = ms - (sec*1000);
+    min = (sec/60);
+    sec = sec - (min*60);
+    ms = (ms/10);
+    sprintf(buffer, "%02d:%02d:%d", min, sec, ms);
+    return buffer;
+}
\ No newline at end of file
diff -r 000000000000 -r 3328857bf625 Stopwatch.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stopwatch.h	Mon Jul 16 19:46:34 2012 +0000
@@ -0,0 +1,20 @@
+#include "stdio.h"
+#include "stdlib.h"
+#include "math.h"
+#include "mbed.h"
+
+class Stopwatch {
+public:
+    Stopwatch();
+    ~Stopwatch();
+    void start();
+    void stop();
+    char* getTime();
+    void countDown(int startTime);
+private:
+    int ms;
+    int sec;
+    int min;
+    char buffer[9];
+    Timer sw;
+};
\ No newline at end of file