From 0e0f5e966afe2a0a60d2d87bebaac9bff644d184 Mon Sep 17 00:00:00 2001 From: kougyokugentou <41278462+kougyokugentou@users.noreply.github.com> Date: Sun, 24 Oct 2021 16:18:16 -0700 Subject: [PATCH] DEMO: Stopwatch utility --- demos/stopwatch2.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 demos/stopwatch2.c diff --git a/demos/stopwatch2.c b/demos/stopwatch2.c new file mode 100644 index 0000000..6fa4697 --- /dev/null +++ b/demos/stopwatch2.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +void main(void) +{ + int h, m, s, ms, col; + + /* Init values */ + h = 0; + m = 0; + s = 0; + ms = 0; + col = 0; + + for(;;) + { + if(kbhit()) + { + getch(); + exit(0); + } + + printf("%dh%dm%ds.%dms",h,m,s,ms); + if( (++col % 1) == 0) printf("\r"); + + ms++; + if(ms > 99) + { + ms = 0; + s++; + } + + if(s > 59) + { + s = 0; + m++; + } + + if(m > 59) + { + m = 0; + h++; + } + + delay(100); + } +} +