Last active
December 31, 2017 11:21
-
-
Save VincentK16/5883464 to your computer and use it in GitHub Desktop.
DS 1307 Simple Sketch
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" | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
RTC_DS1307 RTC; | |
void setup () { | |
Serial.begin(9600); | |
Wire.begin(); | |
RTC.begin(); | |
lcd.begin(20, 4); | |
pinMode(8,OUTPUT); | |
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(__DATE__, __TIME__)); | |
} | |
} | |
void loop () { | |
DateTime now = RTC.now(); | |
lcd.setCursor(0, 0); | |
lcd.print("Digital Clock"); | |
lcd.setCursor(0, 1); | |
lcd.print(now.day(), DEC); | |
lcd.print('/'); | |
lcd.print(now.month(), DEC); | |
lcd.print('/'); | |
lcd.print(now.year(), DEC); | |
lcd.print(' '); | |
lcd.setCursor(0, 2); | |
if (now.hour()<10) | |
lcd.print('0'); | |
lcd.print(now.hour(), DEC); | |
lcd.print(':'); | |
if (now.minute()<10) | |
lcd.print('0'); | |
lcd.print(now.minute(), DEC); | |
lcd.print(':'); | |
if (now.second()<10) | |
lcd.print('0'); | |
lcd.print(now.second(), DEC); | |
lcd.setCursor(0, 3); | |
int dayofweek = now.dayOfWeek(); | |
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 0: | |
lcd.print("Sunday"); | |
break; | |
delay(1000); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment