get paid to paste

SainSmart DS1307 RTC LCD

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

RTC_DS1307 rtc;

void setup () {
   lcd.begin(16, 2);              // start the library
  Serial.begin(9600);

  Wire.begin();

  rtc.begin();

  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); 
     int nmonth  = now.month();
     if (nmonth<10) lcd.print("0"); // inserts leading 0 to maintain display position
     lcd.print(now.month(), DEC);
     lcd.print('/');
     int nday  = now.day();
     if (nday<10) lcd.print("0");
     lcd.print(now.day(), DEC);
     lcd.print('/');
     int nyear  = now.year();
     if (nyear<10) lcd.print("0");
     lcd.print(now.year(), DEC);
     lcd.print(' ');
     lcd.setCursor(0,1);
     int nhour  = now.hour();
     if (nhour<10) lcd.print("0");
     lcd.print(now.hour(), DEC);
     lcd.print(':');
     int nminute  = now.minute();
     if (nminute<10) lcd.print("0");
     lcd.print(now.minute(), DEC);
     lcd.print(':');
     int nsecond  = now.second();
     if (nsecond<10) lcd.print("0");
     lcd.print(now.second(), DEC);
     
    delay(1000);
}

Pasted: Mar 8, 2014, 8:25:20 pm
Views: 396