-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClockForSeg.cpp
More file actions
85 lines (75 loc) · 1.73 KB
/
ClockForSeg.cpp
File metadata and controls
85 lines (75 loc) · 1.73 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* -ClockForSeg Lib-
*
* source code file for ClockForSeg Library
*
* author jihoonkimtech (jihoonkimtech@naver.com)
* (Republic of Korea)
* version V1.0.0
* date 2021-06-18
*/
#include "ClockForSeg.h"
#include <TM1637.h>
#include <ThreeWire.h>
#include <RtcDS1302.h>
#include <Wire.h>
//public
ClockForSeg::ClockForSeg(int _r1, int _r2, int _r3, int _s1, int _s2){
RTC_CLK = _r1;
RTC_DAT = _r2;
RTC_RST = _r3;
SEG_DIO = _s1;
SEG_CLK = _s2;
static ThreeWire wires(RTC_DAT,RTC_CLK,RTC_RST); // IO, SCLK, CE
TW = &wires;
static RtcDS1302<ThreeWire> Rtc((*TW));
RTC = &Rtc;
static TM1637 tm(SEG_CLK, SEG_DIO);
SEG = &tm;
};
void ClockForSeg::init(){
Wire.begin();
RTC->Begin();
RTC->SetIsWriteProtected(false);
RTC->SetIsRunning(true);
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
RTC->SetDateTime(compiled);
//setTime();
//RTC->SetIsWriteProtected(true);
SEG->begin();
SEG->setBrightness(4);
};
void ClockForSeg::displayTime(int _m){
if(_m){
SEG->display(makeTimeStr(1), 0, 0);
delay(500);
SEG->display(makeTimeStr(0), 0, 0);
delay(500);
} else {
SEG->display(makeTimeStr(1), 0, 0);
delay(1000);
}
};
void ClockForSeg::setBright(int _b){
SEG->changeBrightness(_b);
};
//private
void ClockForSeg::setNow(){
RtcDateTime now = RTC->GetDateTime();
};
void ClockForSeg::setTime(){
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
RTC->SetDateTime(compiled);
};
#define countof(a) (sizeof(a) / sizeof(a[0]))
String ClockForSeg::makeTimeStr(int _p){
//setNow();
RtcDateTime t = RTC->GetDateTime();
char _str[10];
snprintf_P(_str,
countof(_str),
(_p)? PSTR("%02u.%02u\0"):PSTR("%02u%02u\0"),
t.Hour(),
t.Minute());
return (String)_str;
};