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());
Stopwatch.cpp@0:3328857bf625, 2012-07-16 (annotated)
- Committer:
- mdomino
- Date:
- Mon Jul 16 19:46:34 2012 +0000
- Revision:
- 0:3328857bf625
Stopwatch library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mdomino | 0:3328857bf625 | 1 | #include "Stopwatch.h" |
mdomino | 0:3328857bf625 | 2 | #include "mbed.h" |
mdomino | 0:3328857bf625 | 3 | |
mdomino | 0:3328857bf625 | 4 | Stopwatch::Stopwatch() { |
mdomino | 0:3328857bf625 | 5 | // constructor |
mdomino | 0:3328857bf625 | 6 | } |
mdomino | 0:3328857bf625 | 7 | |
mdomino | 0:3328857bf625 | 8 | Stopwatch::~Stopwatch() { |
mdomino | 0:3328857bf625 | 9 | // destructor |
mdomino | 0:3328857bf625 | 10 | } |
mdomino | 0:3328857bf625 | 11 | |
mdomino | 0:3328857bf625 | 12 | void Stopwatch::start() { |
mdomino | 0:3328857bf625 | 13 | // Start the timer |
mdomino | 0:3328857bf625 | 14 | sw.start(); |
mdomino | 0:3328857bf625 | 15 | } |
mdomino | 0:3328857bf625 | 16 | |
mdomino | 0:3328857bf625 | 17 | void Stopwatch::stop() { |
mdomino | 0:3328857bf625 | 18 | // Stop the timer |
mdomino | 0:3328857bf625 | 19 | sw.stop(); |
mdomino | 0:3328857bf625 | 20 | } |
mdomino | 0:3328857bf625 | 21 | |
mdomino | 0:3328857bf625 | 22 | char* Stopwatch::getTime() { |
mdomino | 0:3328857bf625 | 23 | // Convert time in milliseconds to 00:00:00 format for output to LCD |
mdomino | 0:3328857bf625 | 24 | // Returns a pointer to a 8 char array in time format |
mdomino | 0:3328857bf625 | 25 | ms = sw.read_ms(); |
mdomino | 0:3328857bf625 | 26 | sec = (ms/1000); |
mdomino | 0:3328857bf625 | 27 | ms = ms - (sec*1000); |
mdomino | 0:3328857bf625 | 28 | min = (sec/60); |
mdomino | 0:3328857bf625 | 29 | sec = sec - (min*60); |
mdomino | 0:3328857bf625 | 30 | ms = (ms/10); |
mdomino | 0:3328857bf625 | 31 | sprintf(buffer, "%02d:%02d:%d", min, sec, ms); |
mdomino | 0:3328857bf625 | 32 | return buffer; |
mdomino | 0:3328857bf625 | 33 | } |