-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockWorks.cpp
More file actions
70 lines (65 loc) · 927 Bytes
/
Copy pathClockWorks.cpp
File metadata and controls
70 lines (65 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* ClockWorks.cpp
*
* Created: 2018-06-28 ¿ÀÀü 6:36:52
* Author: Cakeng (PARK JONG SEOK)
*
* NO LICENCE INCLUDED
* Contact [email protected] to
* use, modify, or share the software for any purpose.
*
*/
#include "ClockWorks.h"
ClockWorks::ClockWorks(uint8_t h, uint8_t m, uint8_t s, uint16_t tickFreq)
{
hours = h;
mins = m;
secs = s;
timeTicks = 0;
timeTicksConstant = tickFreq;
clockKeeping();
}
void ClockWorks::clockKeeping()
{
if(secs > 59)
{
secs -= 60;
mins++;
}
else if (secs < 0)
{
secs += 60;
mins--;
}
if(mins > 59)
{
mins -= 60;
hours++;
}
else if(mins < 0)
{
mins += 60;
hours--;
}
if(hours > 23)
{
hours -= 24;
}
else if(hours < 0)
{
hours += 24;
}
}
void ClockWorks::setTime(uint8_t h, uint8_t m, uint8_t s)
{
hours = h;
mins = m;
secs = s;
clockKeeping();
}
void ClockWorks::getTime(uint8_t& h, uint8_t& m, uint8_t& s)
{
h = hours;
m = mins;
s = secs;
}