Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
projects/sketchbook/shrimpingit/alarmclock/Clock01HardcodeTime/Clock01HardcodeTime.ino
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (35 sloc)
889 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include "RTClib.h" | |
RTC_DS1307 rtc; | |
#define SERIAL_RATE 9600 | |
void setup(){ | |
Serial.begin(SERIAL_RATE); | |
Wire.begin(); | |
rtc.begin(); | |
DateTime now = rtc.now(); | |
if(!rtc.isrunning() || now.year() == 2099){ | |
//time never set since powering RTC chip | |
//set it to a hard-coded time | |
rtc.adjust(DateTime(2016, 3, 21, 01, 24, 0)); | |
} | |
} | |
void loop(){ | |
delay(1000); | |
printIsoDateTime(); | |
} | |
/** Prints a dateTime conforming to ISO8601. */ | |
void printIsoDateTime(){ | |
DateTime now = rtc.now(); | |
Serial.print(now.year(), DEC); | |
Serial.print('-'); | |
Serial.print(now.month(), DEC); | |
Serial.print('-'); | |
Serial.print(now.day(), DEC); | |
Serial.print('T'); | |
Serial.print(now.hour(), DEC); | |
Serial.print(':'); | |
Serial.print(now.minute(), DEC); | |
Serial.print(':'); | |
Serial.print(now.second(), DEC); | |
Serial.println(); | |
} |