How to change the date of the DS3231 automatically that is shown on an LCD without manually changing the codes? Example, when it is 11:59pm of 01.07.2018, when it goes to 00:00am the date will also change to 01.08.2018. Thanks
#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);
// The following lines can be uncommented to set the date and time
// rtc.setTime(06, 58, 40); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(1, 8, 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());
//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());
// Wait one second before repeating :)
delay (1000);
}
why do you think it does not work?
every second your Arduino will do
//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());
so will update both the time and the date
side note — This belongs to the setup()
//Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
matoito:
I want to make the date change whenever the time goes 00:00:00. I have no idea what codes I should use. Should I use if statements? for-loop? etc
are you saying that when the time is 00:00:00 the date shown is still the previous day and has not moved to the new day?
I'll gonna try that library u said and then Imma update you when its working or not. So, when I set the date and time using the codes I used, the date will usually update when the time goes 00:00 for example? Am I right? Hehehe