-
Notifications
You must be signed in to change notification settings - Fork 0
/
RTC_Initialisierung_UTC.ino
90 lines (72 loc) · 1.56 KB
/
RTC_Initialisierung_UTC.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
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
86
87
88
89
90
/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* Set PC to UTC!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
#include <RTClib.h>
#include <avr/sleep.h>
#include <RTClib.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
RTC_DS3231 rtc;
const byte pinLedGreen = 5;
const byte pinLedRed = 4;
const byte pinInterrupt = 2;
bool initializationError = false;
void setup(){
Serial.begin(115200);
if(configureRTC()) {
Serial.println("RTC OK");
}
else {
Serial.println("RTC FAILED");
initializationError = true;
}
if(initializationError) {
flashError();
}
else {
flashOk();
}
}
void loop() {
showTime();
delay(5000);
}
bool configureRTC()
{
if(!rtc.begin()) {
return false;
}
// Uncomment here to set time, comment to just test the currently saved time
////rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
return true;
}
void showTime() {
DateTime now = rtc.now() + TimeSpan(15);
Serial.print(now.day(), DEC);
Serial.print('.');
Serial.print(now.month(), DEC);
Serial.print('.');
Serial.print(now.year(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
delay(1000);
}
void flashOk() {
unsigned long ms = 500;
pinMode(pinLedGreen, OUTPUT);
for(byte i=0; i<5; i++){
digitalWrite(pinLedGreen, HIGH);
delay(ms);
digitalWrite(pinLedGreen, LOW);
delay(ms);
}
}
void flashError(){
pinMode(pinLedRed, OUTPUT);
digitalWrite(pinLedRed, HIGH);
}