Created
September 5, 2012 04:24
-
-
Save brooksware2000/3630408 to your computer and use it in GitHub Desktop.
Example sketch for the DS3234 SPI Real Time Clock (RTC). Prints results to an I2C LCD.
This file contains hidden or 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
/* | |
Demonstration sketch for Hobbybotics Wireless Thermostat/Temperature Node V2.0 using DS3234 RTC. | |
Reads Date and Time. Displays results to LCD | |
*/ | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <RTClib.h> | |
#include <DS3234.h> | |
#include <LCD.h> | |
DS3234 RTC; | |
// create LCD object | |
LCD lcd; | |
void setup() | |
{ | |
lcd.begin(20,4); | |
lcd.clear(); | |
lcd.print("--DS3234 Demo--"); | |
SPI.begin(); | |
RTC.begin(); | |
if (! RTC.isrunning()) // set RTC to date & time this sketch was compiled | |
RTC.adjust(DateTime(__DATE__, __TIME__)); | |
} | |
void loop() | |
{ | |
DateTime now = RTC.now(); | |
int hour = now.hour(); | |
int minute = now.minute(); | |
int second = now.second(); | |
int day = now.day(); | |
int month = now.month(); | |
int year = now.year(); | |
int dayofweek = now.dayOfWeek(); | |
lcd.setCursor(0,1); | |
lcd.print(day); | |
lcd.print("/"); | |
lcd.print(month); | |
lcd.print("/"); | |
lcd.print(year); | |
lcd.print(" "); | |
if (hour < 10){ | |
lcd.print("0"); | |
} | |
lcd.print(hour); | |
lcd.print(":"); | |
if (minute < 10){ | |
lcd.print("0"); | |
} | |
lcd.print(minute); | |
lcd.print(":"); | |
if (second < 10){ | |
lcd.print("0"); | |
} | |
lcd.print(second); | |
if (hour < 12) | |
lcd.print("A"); | |
else | |
lcd.print("P"); | |
lcd.setCursor(0,2); | |
switch (dayofweek) | |
{ | |
case 1: lcd.print("Monday"); break; | |
case 2: lcd.print("Tuesday"); break; | |
case 3: lcd.print("Wednesday"); break; | |
case 4: lcd.print("Thursday"); break; | |
case 5: lcd.print("Friday"); break; | |
case 6: lcd.print("Saturday"); break; | |
case 7: lcd.print("Sunday"); break; | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment