-
Notifications
You must be signed in to change notification settings - Fork 1
/
Clock.ino
60 lines (46 loc) · 1.17 KB
/
Clock.ino
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
#include "ClockAPI.h"
#include "TimeUtils.h"
#include "PathUtils.h"
// -- MAIN LOGIC BEGIN
RTC_Interface rtcClock_;
Time globTime_;
uint32_t micros_;
ClockUI clockUI_;
Gantry gantry_;
HourHand hourHand_;
void clockInterrupt()
{
globTime_.Sec += 1;
globTime_.normalize();
if (globTime_.Sec == 0)
micros_ = 0;
}
uint32_t lastMicros = 0;
uint32_t curMicros = 0;
void setup()
{
// set up RTC
rtcClock_.init(globTime_);
attachInterrupt(digitalPinToInterrupt(SYNCPIN), clockInterrupt, FALLING);
// set up hours and minutes
gantry_.init();
hourHand_.init();
clockUI_.init();
// assign micros_. not perfect but very close
micros_ = globTime_.Sec * 1000000;
curMicros = micros();
lastMicros = curMicros;
}
MinutesPathMapper minutesPath_;
HourPosMapper hourPath_;
void loop()
{
curMicros = micros();
micros_ += (curMicros - lastMicros);
lastMicros = curMicros;
clockUI_.update(globTime_, rtcClock_, curMicros);
auto point = minutesPath_.getPos(globTime_.Min, micros_);
gantry_.chase_point(point, curMicros);
auto angle = hourPath_.getPos(globTime_, micros_);
hourHand_.chase_angle(angle, curMicros);
}