So I recently bought a PCF Real time clock module for my Arduino nano. The intended purpose is to cause an action to happen two times a day. I have two problems. My code is pasted below. One is that when I look in the serial monitor, the time will constantly reset itself every time I close and reopen it. I just want to make sure that when the device is autonomous it will actually count the time. The second thing I need help with is the if-statement in the void loop. It does not work, and I never see the then-statement in my code. Is there a problem with how I am using the now function? Thanks!
- Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include "RTClib.h"
RTC_PCF8523 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int timer = 0;
int GREEN_LED = 12;
int RED_LED = 11;
int BUTTON = 4;
void setup() {
while (!Serial) {
delay(1); // for Leonardo/Micro/Zero
}
Serial.begin(57600);
if (! rtc.begin()){
Serial.println("Couldn't find RTC");
while(1);
}
if (! rtc.initialized()) {
Serial.println("RTC is NOT currently running");
}
rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
void loop() {
DateTime now = rtc.now();
/*Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");*/
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
if ((now.minute(), DEC) == 1) {
Serial.println("Yay!"); //not working
}
delay(3000);
}