Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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);
- }
- if (! rtc.isrunning()) {
- Serial.println("RTC is NOT running!");
- // following line sets the RTC to the date & time this sketch was compiled
- // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- // This line sets the RTC with an explicit date & time, for example to set
- // January 21, 2014 at 3am you would call:
- rtc.adjust(DateTime(2016, 11, 19, 19, 45, 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement