Please clarify one of my doubt.I am not an expert in programming.
DS3231 with 16 x 2 LCD display I made. The clock showing min and seconds in single digit. I want it to be in two digit format. Can anybody help me to solve the issue ?
The code I am used is as follows
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
char daysOfTheWeek[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
int Day;
int Month;
int Year;
int Secs;
int Minutes;
int Hours;
String dofweek; // day of week
String myDate;
String myTime;
// for the 16x2 LCD
#define rs 9
#define en 8
#define d4 7
#define d5 6
#define d6 5
#define d7 4
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup ()
{
Serial.begin(9600);
lcd.begin(16, 2);
delay(3000); // wait for console opening
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 ()
{
DateTime now = rtc.now();
lcd.clear();
Day = now.day();
Month = now.month();
Year = now.year();
Secs = now.second();
Hours = now.hour();
Minutes = now.minute();
dofweek = daysOfTheWeek[now.dayOfTheWeek()];
myDate = myDate +dofweek+ " "+ Day + "/" + Month + "/" + Year ;
myTime = myTime + Hours +":"+ Minutes +":" + Secs ;
// send to serial monitor
Serial.println(dofweek);
Serial.println(myDate);
Serial.println(myTime);
//Print on lcd
lcd.setCursor(0,0);
lcd.print(myDate);
lcd.setCursor(0,1);
lcd.print(myTime);
myDate = "";
myTime = "";
delay(1000);
}
My display of time is attaching
Regards
VINOD, India