-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetRTCTime_FirstTime.ino
53 lines (45 loc) · 1.47 KB
/
setRTCTime_FirstTime.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
/*
_ _ ______ _____ _____
(_) | | ____| __ \_ _|
_ __ ___ _____| | |__ | | | || |
| '_ \| \ \/ / _ \ | __| | | | || |
| |_) | |> < __/ | |____| |__| || |_
| .__/|_/_/\_\___|_|______|_____/_____|
| |
|_|
www.pixeledi.eu | twitter.com/pixeledi
Set RTC Time for the first Time | V1.0 | 06/2022
*/
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
Serial.begin(9600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
//just first time
//rtc.adjust(DateTime(2022, 5, 27, 15, 46, 0)); // <----------------------SET TIME AND DATE: YYYY,MM,DD,HH,MM,SS
delay(100);
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(3000); //Print date and time every 3 sec
}