-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path_rtc.h
80 lines (67 loc) · 1.75 KB
/
_rtc.h
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
#ifndef _RTC_H
#define _RTC_H
//Defines the min function as somewhere the function stops working.
#define min(a,b) ((a)<(b)?(a):(b))
#define countof(a) (sizeof(a) / sizeof(a[0]))
#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS1307.h>
#include <SimpleTimer.h>
extern SimpleTimer timer;
void ringAlarm(int,int,String);
RtcDS1307<TwoWire> Rtc(Wire);
//Defines the init of RTC
void rtcInit()
{
Rtc.Begin();
pinMode (BUZZER_PIN, OUTPUT);
}
//Prints the date and time to the console
void printDateTime(const RtcDateTime& dt)
{
char datestring[20];
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}
//Events fired in the background to update the time variable and properly format it to be displayed on the Display
void TimeUpdateEvent()
{
RtcDateTime now = Rtc.GetDateTime();
int hour = now.Hour();
int minutes = now.Minute();
int seconds = now.Second();
String AMPM = "AM";
if (hour == 0)
{
hour = 12;
}
if (hour > 12)
{
hour -= 12;
AMPM = "PM";
}
timeIs = String(hour) + ":" + String(minutes) + AMPM;
// Serial.println(timeIs + String(seconds));
ringAlarm(hour,minutes,AMPM);
}
//Event that is fired once the unit starts.
void TimeAutoStartEvent()
{
if (State == START_STATE)
{
Blynk.virtualWrite(SHOW_TIME_BUTTON_WIDGET, HIGH);
Blynk.virtualWrite(TEXT_SCROLL_BUTTON_WIDGET, HIGH);
State = TIME_STATE;
timer.enable(Timer[MSG_TIMER]);
x = matrix->width();
matrix->setBrightness(brightness);
}
}
#endif