Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <TimeLib.h>
- #include <Wire.h>
- #include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
- #include <LiquidCrystal.h>
- void digitalClockDisplay();
- void printDigits(int digits);
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- // -------------------------------------------
- // Digital Clock with RTC
- // www.ardukode.blogspot.com
- // -------------------------------------------
- void setup() {
- lcd.begin(16,2);
- while (!Serial);
- delay(200);
- }
- void loop() {
- tmElements_t tm;
- if (RTC.read(tm))
- {
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.println("Tgl:");
- printDigits(tm.Day);
- lcd.print(".");
- printDigits(tm.Month);
- lcd.print(".");
- lcd.print(tmYearToCalendar(tm.Year));
- lcd.setCursor(0,1);
- lcd.print("Jam: ");
- printDigits(tm.Hour);
- lcd.print(":");
- printDigits(tm.Minute);
- lcd.print(":");
- printDigits(tm.Second);
- }
- else
- {
- if (RTC.chipPresent())
- {
- lcd.print("DS1307 Stop");
- }else
- {
- lcd.print("DS1307 Error");
- }
- delay(9000);
- }
- delay(1000);
- }
- void printDigits(int digits){
- // utility function for digital clock display: prints preceding colon and leading 0
- if (digits >= 0 && digits < 10)
- {
- lcd.write('0');
- }
- lcd.print(digits);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement