Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<Wire.h>
- #include "RTClib.h"
- RTC_DS3231 rtc;
- unsigned long previousMillis = 0; // will store last time LED was updated
- const long interval = 1000;
- void setup() {
- Serial.begin(9600);
- // put your setup code here, to run once:
- if (! rtc.begin()) {
- Serial.println(F("Couldn't find RTC"));
- while (1);
- }
- if (rtc.lostPower()) {
- Serial.println(F("RTC lost power, lets set the time!"));
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- }
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- DateTime now = rtc.now();
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval)
- {
- previousMillis = currentMillis;
- Serial.print(now.year(), DEC);
- Serial.print( "/" );
- Serial.print(now.month(), DEC);
- Serial.print( "/" );
- Serial.print(now.day(), DEC),
- Serial.print( " " );
- Serial.print(now.hour(), DEC);
- Serial.print( ":" );
- Serial.print(now.minute(), DEC);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment