Never mind, I got it to work!
You have a misplaced curly bracket. See the comment marked with ***************.
#include <ThreeWire.h>
#include <RtcDS1302.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
ThreeWire myWire(A2, A0, A1); // IO, SCLK, CE
RtcDS1302<ThreeWire> Rtc(myWire);
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27
byte smile[8] =
{
B00000,
B00000,
B01010,
B00000,
B10001,
B01110,
B00000,
B00000
};
void setup()
{
Serial.begin(57600);
Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);
Rtc.Begin();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();
if (!Rtc.IsDateTimeValid())
{
// Common Causes: 1) first time you ran and the device wasn't running yet 2) the battery on the device is low or even missing
Serial.println("RTC lost confidence in the DateTime!");
Rtc.SetDateTime(compiled);
}
if (Rtc.GetIsWriteProtected())
{
Serial.println("RTC was write protected, enabling writing now");
Rtc.SetIsWriteProtected(false);
}
if (!Rtc.GetIsRunning())
{
Serial.println("RTC was not actively running, starting now");
Rtc.SetIsRunning(true);
}
RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
Serial.println("RTC is newer than compile time. (this is expected)");
else
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
lcd.init(); //initialize the lcd
lcd.backlight();
lcd.createChar(1, smile);
lcd.setCursor ( 0, 2 );
lcd.write(1);
lcd.setCursor (2, 2);
lcd.print("You've got this!");
lcd.setCursor (19, 2);
lcd.write(1);
lcd.setCursor ( 1, 3 );
lcd.print("Fruit/Veg? Vit D?");
}
/*********************************************************/
void loop()
{
RtcDateTime now = Rtc.GetDateTime();
now -= 60;
printDateTime(now);
if (!now.IsValid())
{
// Common Causes: 1) the battery on the device is low or even missing and the power line was disconnected
Serial.println("RTC lost confidence in the DateTime!");
}
delay(1000);
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
char datestring[20];
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u"),
dt.Day(), dt.Month(), dt.Year());
char timestring[20];
snprintf_P(timestring,
countof(timestring),
PSTR("%02u:%02u"),
dt.Hour(), dt.Minute());
int dow = dt.DayOfWeek();
switch (dow)
{
case 1:
lcd.print("Mon");
break;
case 2:
lcd.print("Tue");
break;
case 3:
lcd.print("Wed");
break;
case 4:
lcd.print("Thu");
break;
case 5:
lcd.print("Fri");
break;
case 6:
lcd.print("Sat");
break;
case 0:
lcd.print("Sun");
break;
}
//} ************** misplaced
lcd.setCursor ( 7, 0 ); // go to the top left corner
lcd.print(timestring);
lcd.setCursor (5, 1);
lcd.print(datestring);
}
If you had used the IDE autoformat tool (ctrl-t or Tools, Auto Format) the location of the error would have been visible.
in the future please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags.
Karma for code tags on first post. Not many new members bother to read the guidelines.
Just a note, it is frowned upon to delete the content of your question after finding a solution. Better to just reply that the problem has been solved, preferably with an explanation of what was wrong if needed, that way others with similar problems may benefit from the answer in the future.
You can also edit the title to add [Solved] or something similar to let others know the solution has been found.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.