So trying to figure it out. Note: I can remove power and the board retains time just fine so my battery is good.
This last night I kept the board powered from the UNO and didn't reboot the UNO nor did I unplug the DS3231 and it still lost power.
I have "adjust time" commented out so it's not a matter of me resetting the time by accident in my code. See code below.
Please advise,
Thanks
Code: Select all
#include "RTClib.h"
RTC_DS3231 rtc;
int buttonState = 0; // variable for reading the pushbutton status
const int buttonPin = 2; // the number of the pushbutton pin
char days[7][10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const int ledPin = 13;
int strike_hours[10] = {9,10,11,12,13,14,15,16,17,18};
int number_of_strikes = 0;
void strike_bell() {
number_of_strikes = 0;
DateTime now = rtc.now();
number_of_strikes = number_of_strikes + now.hour();
if (now.hour() >= 13) {
number_of_strikes = number_of_strikes - 12;
}
for(int y = 0; y < number_of_strikes; y++){
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(2000);
}
}
void setup () {
Serial.begin(9600);
rtc.begin();
pinMode(ledPin, OUTPUT); // Initialize the LED_BUILTIN pin as an output
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:
//rtc.adjust(DateTime(2020, 02, 19, 17, 9, 00));
}
void loop () {
DateTime now = rtc.now();
for(int x = 0; x < 10; x++) {
if (now.hour() == strike_hours[x] && now.minute() == 00 && now.second() == 00) {
strike_bell(); // strike the bell
delay(1);
} else {
digitalWrite(ledPin, LOW); // keep LED off:
}
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(days[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();
Serial.print("Temperature: ");
Serial.print(rtc.getTemperature());
Serial.println(" C");
Serial.println();
delay(100);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(1);
} else {
digitalWrite(ledPin, LOW); // keep LED low
delay(1);
}
}
}