Ok I changed it per your recommendation. Nothing happened so far still, the buttons still don't do anything. I put the rtc.adjust(DateTime(F(_DATE_), F(_TIME_))); back in voidsetup because the time get all weird when I removed it. Sometime it will start counting from 00.00, sometimes it will display time but not from my time zone.
//this version is working, don't change it. Make a copy instead.
#include <Adafruit_I2CRegister.h>
#include <RTClib.h>
RTC_DS3231 rtc;
//set up for the Shift registers and numbers
//check the datasheet for the SN74HC595 to see the idividual pins
#define Hourbutton 8//button used to adjust the hour
#define Minutebutton 9//button used to adjust the minutes
#define DS_pin 4//blue
#define STCP_pin 5//yellow
#define SHCP_pin 6//green
//color coded so you don't blows it up
int numbers[10] {126, 48, 109, 121, 51, 91, 95, 112, 127, 123}; //use [int digits [10] { 1, 79, 18, 12, 76, 36, 32, 15, 0, 4};] instead if
//your display is the common Annode type. I did all the binary conversion, you are welcome.
uint8_t digits[4]; //int d1; int d2; int d3; int d4;// has to define all of these, they reperesent the individual digits and the time number
int hbstate;
int mbstate;
int lasthbstate = 0;
int lastmbstate = 0;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
pinMode(Hourbutton, INPUT);
pinMode(Minutebutton, INPUT);
pinMode(DS_pin, OUTPUT);
pinMode(STCP_pin, OUTPUT);
pinMode(SHCP_pin, OUTPUT);
// initializing the rtc
rtc.begin();
//if (! rtc.begin()) {
//Serial.println("Couldn't find RTC");
//Serial.flush();
//while (1) delay(10);}
//if (rtc.lostPower()){
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
//rtc.adjust(DateTime(2026,6,6,22,40,30);// This line sets the RTC with the time from the pc when compile
}
void loop() {
//DateTime hour = now.hour();
//DateTime hour = now.minute();
DateTime now = rtc.now();
uint8_t hour = now.hour();
uint8_t minute = now.minute();
int hreading = digitalRead(Hourbutton);
int mreading = digitalRead(Minutebutton);
///////////////////////////////////////////////////////////////Formula to display Hours
digits[1]= ((hour/10)%10);//formula for the first digit
digits[2]= (hour%10);//formula for the second digit
//////////////////////////////////////////////////////////////Formua to display Minutes
digits[3]= ((minute/10)%10);//formula for the third digit
digits[4]= (minute%10);//formula for the fourth digit
if (hreading != lasthbstate) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (hreading != hbstate) {
hbstate = hreading;
if (hbstate == 1) {
if (hour == 24){
hour = 0;
rtc.adjust(now.hour());
}
else {
hour++;
rtc.adjust(now.hour());
}
}
}
}
if (mreading != lastmbstate) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (mreading != mbstate) {
mbstate = mreading;
if (mbstate == 1) {
if (minute == 60){
minute = 0;
rtc.adjust(now.minute());
}
else {
minute++;
rtc.adjust(now.minute());
}
}
}
}
// save the reading. Next time through the loop, it'll be the lastButtonState:
digitalWrite(STCP_pin, LOW);
//The lines of code below is the shiftout command
//use least LSBFIRST instead of MSBFIRST
shiftOut(DS_pin, SHCP_pin, LSBFIRST, numbers[digits[4]]); // shift in the digit, last digit.
shiftOut(DS_pin, SHCP_pin, LSBFIRST, numbers[digits[3]]); // shift in the digit, third digit.
shiftOut(DS_pin, SHCP_pin, LSBFIRST, numbers[digits[2]]); // shift in the digit, second digit.
shiftOut(DS_pin, SHCP_pin, LSBFIRST, numbers[digits[1]]); // shift in the digit, first digit.
//The sequenece is important
digitalWrite(STCP_pin, HIGH); // flash the digit in the correct place
delay (100);
}