Hello Everyone,
There is a problem with my software. As of now, I am currently working on a project using an Arduino Uno board, an LCD Module and the DS1307 module. It's intended goal is to initially display "Watch Clock" and then after a certain period of time it displays the time that is get from the Serial Monitor using the DS1307 Module. Currently, it only displays the initial "Watch Clock" text that I have set up in my void setup(). Maybe someone can help me with this predicament and help me understand something I am not. This is my code.
#include <LiquidCrystal.h>
#include <DS3232RTC.h>
#include <Streaming.h>
#define buttonPin_1 8
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd (rs, en, d4, d5, d6, d7);
DS3232RTC myRTC;
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
lcd.setCursor(4, 0);
Serial << F( "\n" __FILE__ "\n" __DATE__ " " __TIME__ "\n" );
myRTC.begin();
setSyncProvider(myRTC.get);
Serial << F("RTC Sync");
Serial << endl;
lcd.print("World Clock");
pinMode(buttonPin_1, INPUT);
}
void loop() {
static time_t tLast;
time_t t;
tmElements_t tm;
// check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s
if (Serial.available() >= 12) {
int y = Serial.parseInt();
if (y >= 100 && y < 1000)
Serial << F("Error: Year must be two digits or four digits!") << endl;
else {
if (y >= 1000)
tm.Year = CalendarYrToTm(y);
else // (y < 100)
tm.Year = y2kYearToTm(y);
tm.Month = Serial.parseInt();
tm.Day = Serial.parseInt();
tm.Hour = Serial.parseInt();
tm.Minute = Serial.parseInt();
tm.Second = Serial.parseInt();
t = makeTime(tm);
myRTC.set(t); // use the time_t value to ensure correct weekday is set
setTime(t);
Serial << F("RTC set to: ");
printDateTime(t);
Serial << endl;
// dump any extraneous input
while (Serial.available() > 0) Serial.read();
}
}
t = now();
if (t != tLast) {
tLast = t;
printDateTime(t);
printTimeLCD(t);
Serial << endl;
}
}
void printDateTime(time_t t)
{
printDate(t);
Serial << ' ';
printTime(t);
}
// print time to Serial
void printTime(time_t t)
{
printI00(hour(t), ':');
printI00(minute(t), ':');
printI00(second(t), ' ');
}
// print date to Serial
void printDate(time_t t)
{
printI00(day(t), 0);
Serial << monthShortStr(month(t)) << _DEC(year(t));
}
// Print an integer in "00" format (with leading zero),
// followed by a delimiter character to Serial.
// Input value assumed to be between 0 and 99.
void printI00(int val, char delim)
{
if (val < 10) Serial << '0';
Serial << _DEC(val);
if (delim > 0) Serial << delim;
return;
}
void printTimeLCD(time_t t){
if(Serial.available() && digitalRead(buttonPin_1) == HIGH){
delay(100);
lcd.clear();
lcd.setCursor(4, 0);
while (Serial.available() > 0) {
lcd.setCursor(0, 1);
lcd.write(Serial.read());
}
}
}`Use code tags to format code for the forum`
type or paste code here