Tuesday 6 August 2019

DS3231-ARDUINO KEYPAD CLOCK


DS3231 CLOCK WITH ARDUINO LCD KEYPAD CODE

//CODE
//Maiden Arduino project by  'VU2WSX' GENERAL GRADE RADIO AMATUER FROM INDIA
//Arduino clock with highly accurate RTC DS3231 with LCD keypad
//Un comment the lines to bring active
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include "LCDKeypad.h"
RTC_DS3231 rtc;
// The LCD screen
LCDKeypad lcd;

char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

void setup ()
{
  Serial.begin(9600);
  delay(3000); // wait for console opening
   lcd.begin(16,2);
   lcd.print("Name");//Type your name
   
   delay(3000);

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
 
  // Comment out below lines once you set the date & time.
    // Following line sets the RTC to the date & time this sketch was compiled
   // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 
    // Following line sets the RTC with an explicit date & time
    // for example to set January 27 2017 at 12:56 you would call:
     //rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0));
  }
}

void loop ()
{
  //Remove the comments for diplay blinking
 // lcd.clear();
 //delay(500);


    DateTime now = rtc.now();

    DateTime future (now );//+ TimeSpan(7,0,0,30));
   
    Serial.println("Future Date & Time (Now + 7days & 30s): ");
    lcd.setCursor(0,0);
    //lcd.leftToRight();
      if( future.day()<10)
   lcd.print("0");
    lcd.print(future.day(), DEC);
    lcd.print('/');
    if( future.month()<10)
   lcd.print("0");
    lcd.print(future.month(), DEC);
    lcd.print('/');
    lcd.print(future.year(), DEC); 
    lcd.print(' '); 
    lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
   
    lcd.setCursor(4,1);
    if( future.hour()<10)
   lcd.print("0");     
   lcd.print(future.hour(), DEC);
   lcd.print(':');
 
   if( future.minute()<10)
   lcd.print("0"); 
   lcd.print(future.minute(), DEC);
   lcd.print(':');
 
   if( future.second()<10)
   lcd.print("0");
   lcd.print(future.second(), DEC);
   
    delay(1000);
   // void loop() {
 // Removebottom comments to activate the commands for scrolling display
    // scroll one position left:
        //lcd.scrollDisplayLeft();
    //lcd.scrollDisplayRight();
     // wait a bit:
   // delay(100);
 
}