Mission 8 - Real Time Clock
 DuinoKit Essentials   Started by Daniel Alich   2017-06-27 21:38:57 -04:00   Comments: 1    Viewed: 132

  1. Daniel Alich
    Daniel Alich Member Staff Member


    #include <Wire.h>
    #include "RTClib.h"
    #include <LiquidCrystal.h>

    RTC_DS1307 RTC;
    //(RS,E,D4,D5,D6,D7);
    LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

    void setup () {
    Serial.begin(9600);
    lcd.begin(16, 2);
    Wire.begin();
    RTC.begin();

    if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
    }
    }

    void loop () {
    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(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();


    lcd.setCursor(0, 0);
    lcd.print("TIME: ");
    lcd.print(now.hour(), DEC);
    lcd.print(":");
    lcd.print(now.minute(), DEC);
    lcd.print(":");
    lcd.print(now.second(), DEC);

    lcd.setCursor(0, 1);
    lcd.print("DATE: ");
    lcd.print(now.year(), DEC);
    lcd.print("/");
    lcd.print(now.month(), DEC);
    lcd.print("/");
    lcd.print(now.day(), DEC);

    delay(1000);
    }
    Daniel Alich, 2017-06-27 21:38:57 -04:00
  2. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!