i have 16x2 lcd and i have DS3231 rtc I'm using to make a clock and whenever i write lcd.print(rtc.hour()); it keeps repeatedly printing it like:17 18 19
the code is not finished yet though
and if i try it with a sketch that initialises the lcd and just prints hello world in void loop it works
i wrote some new code to display the time and the same thing keeps happening
#include "Arduino.h"
#include "uRTCLib.h"
#include <LiquidCrystal.h>
// uRTCLib rtc;
uRTCLib rtc(0x68);
int hour;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
bool night = false;
const int buttonPin = 7;
int buttonState = 0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
delay(3000);// wait for console opening
URTCLIB_WIRE.begin();
pinMode(buttonPin, INPUT);
// Comment out below line once you set the date & time.
// Following line sets the RTC with an explicit date & time
// for example to set January 13 2022 at 12:56 you would call:
// rtc.set(second, minute, hour, dayOfWeek, dayOfMonth, month, year)
// set day of week (1=Sunday, 7=Saturday)
}
void loop() {
rtc.refresh();
lcd.setCursor(0,0);
lcd.print(rtc.hour());
lcd.print(":");
lcd.print(rtc.minute());
lcd.print(":");
lcd.print(rtc.second());
delay(1000);
}
Try this code.
I changed the buttonPin pin to 8 and added a line to clear the LCD at the end after the 1 sec delay.
#include "Arduino.h"
#include "uRTCLib.h"
#include <LiquidCrystal.h>
// uRTCLib rtc;
uRTCLib rtc(0x68);
int hour;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
bool night = false;
const int buttonPin = 8;
int buttonState = 0;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
delay(3000);// wait for console opening
URTCLIB_WIRE.begin();
pinMode(buttonPin, INPUT);
// Comment out below line once you set the date & time.
// Following line sets the RTC with an explicit date & time
// for example to set January 13 2022 at 12:56 you would call:
// rtc.set(second, minute, hour, dayOfWeek, dayOfMonth, month, year)
// set day of week (1=Sunday, 7=Saturday)
}
void loop() {
rtc.refresh();
lcd.setCursor(0,0);
lcd.print(rtc.hour());
lcd.print(":");
lcd.print(rtc.minute());
lcd.print(":");
lcd.print(rtc.second());
delay(1000);
lcd.clear();
}