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
Stopwatch.cpp
00001 #include "Stopwatch.h" 00002 #include "mbed.h" 00003 00004 Stopwatch::Stopwatch() { 00005 // constructor 00006 } 00007 00008 Stopwatch::~Stopwatch() { 00009 // destructor 00010 } 00011 00012 void Stopwatch::start() { 00013 // Start the timer 00014 sw.start(); 00015 } 00016 00017 void Stopwatch::stop() { 00018 // Stop the timer 00019 sw.stop(); 00020 } 00021 00022 void Stopwatch::reset() { 00023 // Reset the timer 00024 sw.reset(); 00025 } 00026 00027 char* Stopwatch::getTime() { 00028 // Convert time in milliseconds to 00:00:00 format for output to LCD 00029 // Returns a pointer to a 8 char array in time format 00030 ms = sw.read_ms(); 00031 sec = (ms/1000); 00032 ms = ms - (sec*1000); 00033 min = (sec/60); 00034 sec = sec - (min*60); 00035 ms = (ms/10); 00036 sprintf(buffer1, "%02d:%02d:%02d", min, sec, ms); 00037 return buffer1; 00038 } 00039 00040 char* Stopwatch::getTimeFshort() { 00041 // Convert time in milliseconds to 0:00:0 format for output to LCD 00042 // Returns a pointer to a 6 char array in time format 00043 ms1 = sw.read_ms(); 00044 sec = (ms1/1000); 00045 ms1 = ms1 - (sec*1000); 00046 min = (sec/60); 00047 sec = sec - (min*60); 00048 ms1 = (ms1/100); 00049 sprintf(buffer2,"%1d:%02d:%1d", min, sec, ms1); 00050 return buffer2; 00051 }
Generated on Wed Jul 13 2022 15:17:06 by
1.7.2
