The code below shows the date and time that I set on the DS3231 module. My problem is that the time isn't moving on the LCD. The displayed time will only change whenever I reopen the serial monitor. What should I do?
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DS3231.h>
// Init the DS3231 using the hardware interface
#define I2C_ADDR 0x3F //Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
//Initialise the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
DS3231 rtc(SDA, SCL);
void setup()
{
// Setup Serial connection
Serial.begin(115200);
// Initialize the rtc object
rtc.begin();
//Define the LCD as 16 column by 2 rows
lcd.begin (16, 2);
//Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
//goto first column (column 0) and first line (Line 0)
lcd.setCursor(0, 0);
//Print at cursor Location
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
//goto first column (column 0) and second line (line 1)
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());
// The following lines can be uncommented to set the date and time
// rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
// rtc.setTime(06, 58, 40); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(1, 7, 2018); // Set the date to January 1st, 2014
}
void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
}