in this code, I am having the error 'time_t was not declared in the scope" for context this is an Arduino nano, and I am connected to a DS 3231 through analog pins A4 and A5, I downloaded the DS 3231 library too so there's no problems with that, so I don't know why this error is happening.
heres my code:
void setup() {
Serial.begin(115200);
delay(200);
pinMode(5, INPUT);
}
int sec_prev = 0; // Global Variable
void loop() {
int seconds, minutes, hours;
time_t total_seconds = time(0);
struct tm* ct = localtime(&total_seconds);
seconds = ct->tm_sec;
minutes = ct->tm_min;
hours = ct->tm_hour;
>
// Turn on the light from 3pm to 4pm
if (hours == 15) {
digitalWrite(5, HIGH));
delay(180000);
}
else
digitalWrite(5, LOW));
if (seconds != sec_prev) {
sec_prev = seconds;
if (hours < 10)
Serial.print('0');
Serial.print(hours);
Serial.print(':');
if (minutes < 10)
Serial.print('0');
Serial.print(minutes);
Serial.print(':');
if (seconds < 10)
Serial.print('0');
Serial.println(seconds);
}
}
I added the #include which I forgot to add and since it didn't work, I confirmed it has to do with an external library I don't have installed, do you have any suggestions on where to look for such a library, because the only places I've gone is through the DS 3231 or other RTC models libraries and I can't find one that fix's the problem.
Which library did you include? The sketch will compile (after correcting a few typing errors) using the standard time library ( #include <time.h> ).
Best thing is to look at the examples from the DS3231 library that you have installed, that will show the functions specific to that library.
Personally I like to use the Time library (by Paul Stoffregen) and the DS3232RTC library (by J Christensen), and yes that is DS3232, it also works with the DS3231.
thank you for the solution, that error is fixed however when I try to define the DS 3231 as an object it doesn't work even though I downloaded the proper library for it, for example when I try:
#include <DS3231.h>
I know for a fact this should work because I have a DS 3231 and I have the library that goes with this example which supports the DS 3231 (obviously) and I'm including it before void setup so it should work, but it's not...
the error message I'm getting is "exit status 1, DS3231.h: No such file or directory"
to make sure I'm not doing anything wrong can you share the code you applied the include statement in or the example from the library. This will help me tell whether it's my computer to blame if it doesn't work or if it does work then I must be doing something wrong.
I just added the include line to the Blink Without Delay example sketch, the DS3231_RTC library has no example sketches. That library is the only library I have installed with the file DS3231.h