I am working on a larger remote monitoring project and I am adding a DS1307 to the MEGA2560 R3. I figured that I would start EASY and work the code into the big program, so I found some code on the forum from years ago. Needless to say with a few lines of code I hit a wall. I have looked at numerous FAQ’s and was unable to resolve the issue. I probably should change the hourly do something to a minute timed do something, for debugging.
Has to be some dumb mistake I made.
I have inserted the code and error message below.
#define DS1307_h
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <RTClib.h>
void setup()
{
now = rtc.now();
previousHour = now.hour();
}
void loop()
{
now = rtc.now(); // This is the line of code that is highlighted in the error message
if ( now.hour() != previousHour )
{
previousHour = now.hour();
DoSomethingEveryHour();
}
}
void DoSomethingEveryHour()
{
Serial.println("Doing Something Now");
{
}
ERROR msg:
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\Users\Donald\Documents\Arduino\Time_-_DoingSomethingNow\Time_-_DoingSomethingNow.ino: In function 'void setup()':
Time_-_DoingSomethingNow:9:10: error: 'rtc' was not declared in this scope
now = rtc.now();
^
Time_-_DoingSomethingNow:10:4: error: 'previousHour' was not declared in this scope
previousHour = now.hour();
^
Time_-_DoingSomethingNow:10:23: error: request for member 'hour' in 'now', which is of non-class type 'time_t() {aka long unsigned int()}'
previousHour = now.hour();
^
C:\Users\Donald\Documents\Arduino\Time_-_DoingSomethingNow\Time_-_DoingSomethingNow.ino: In function 'void loop()':
Time_-_DoingSomethingNow:15:10: error: 'rtc' was not declared in this scope
now = rtc.now();
^
Time_-_DoingSomethingNow:17:13: error: request for member 'hour' in 'now', which is of non-class type 'time_t() {aka long unsigned int()}'
if ( now.hour() != previousHour )
^
Time_-_DoingSomethingNow:17:23: error: 'previousHour' was not declared in this scope
if ( now.hour() != previousHour )
^
Time_-_DoingSomethingNow:19:27: error: request for member 'hour' in 'now', which is of non-class type 'time_t() {aka long unsigned int()}'
previousHour = now.hour();
^
Time_-_DoingSomethingNow:20:29: error: 'doSomethingEveryHour' was not declared in this scope
doSomethingEveryHour();
^
Time_-_DoingSomethingNow:23:4: error: a function-definition is not allowed here before '{' token
{
^
Time_-_DoingSomethingNow:27:1: error: expected '}' at end of input
}
^
exit status 1
'rtc' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.