# Need help adjusting time on Seven Segment Display clock

**URL:** <https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319>\
**Category:** Programming\
**Created:** [May 29, 2026, 11:59am UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319 "2026-05-29T11:59:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [May 29, 2026, 11:59am UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/1 "2026-05-29T11:59:25Z")

</div>

Hello, I have built a seven segment display clock that have the capability to have its minute and hour number increase via button press. However, I am having an issue where if I let go of the minute/ hour button, the minute/hour number will immediately revert back to their original state. Can someone help me figure out how to permanently adjust the time? Thank you. I can not post the code as a file so I will have the entire thing paste down here.

```arduino
//this version is working, don't change it. Make a copy instead.
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_GenericDevice.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Adafruit_SPIDevice.h>
//renember to include the entire Adafruit BusIO library, the original <Adafruit_I2CRegister.h> library is missing for some reason
#include <RTClib.h>
RTC_DS3231 rtc;
//set up for the Shift registers and numbers
//check the datasheet for the SN74HC595 to see the individual 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.
int digits[4]; //int d1; int d2; int d3; int d4;// has to define all of these, they represents the individual digits and the time number
int hbstate;
int mbstate;
int minute;
int hour;

void setup() {
pinMode(Hourbutton, INPUT);
pinMode(Minutebutton, INPUT);
pinMode(DS_pin, OUTPUT);
pinMode(STCP_pin, OUTPUT);
pinMode(SHCP_pin, OUTPUT);
hbstate = 0;
mbstate = 0;
// initializing the rtc
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    Serial.flush();
    while (1) delay(10);
  }
  // When time needs to be set on a new device, or after a power loss, 
  //the following line sets the RTC to the date & time this sketch was compiled
   if (rtc.lostPower()) {
  rtc.adjust(DateTime(F( __DATE__ ), F( __TIME__ )));// This line sets the RTC with the time from the pc when compiled
    //rtc.adjust(DateTime(2026, 4, 21, 11, 55, 30));//uncomment this line once to manually set the time
  }
//The entire if section above enable the RTC to read correct time, do not delete. thanks Nuetral, I owe you one.
  rtc.disable32K();
}

void loop() {
    //minute = now.minute();
    //hour = now.hour();
    hbstate = digitalRead(Hourbutton);
    mbstate = digitalRead(Minutebutton);
    DateTime now = rtc.now();
    //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 (hbstate == HIGH){
      if (hour == 25){
        hour = 1;
      }
      else{
        hour = now.hour() + 1;
      }
      }
      else{
        hour = now.hour();
      }
    if (mbstate == HIGH){
      if (minute == 61){
        minute = 1;
      }
      else{
        minute = now.minute() + 1;
      }
    }
      else{
        minute = now.minute();
      }
    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);
   
}

```

---

<div class="post-metadata">

**Author:** ![HazardsMind](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hazardsmind/32/215209_2.png) [@HazardsMind](https://forum.arduino.cc/u/HazardsMind)\
**Post date:** [May 29, 2026, 12:24pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/2 "2026-05-29T12:24:31Z")

</div>

At no point do you actually update the hours or minutes on RTC module, you just read from it. So once you let go of either button, it will read the current value instead of the new one that you wanted it to be changed to.

Instead of always reading the current hour or minute. Have them read into new hour and minute variables first, inside your setup function and just manipulate the hour and minute afterwards in the loop. Think of these variables as offsets.

Btw, you might want to clean up the code a bit. It’s a little hard to read, even though it’s not very long.

---

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [May 29, 2026, 12:44pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/3 "2026-05-29T12:44:45Z")

</div>

So do I need to create a new int for new hour and new minute, and by update do you mean using the rtc.adjut()? For the "read into new hour and minute variable first", are you suggesting that I move this entire section section

```arduino
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

```

into void setup? I do need to clean the code afterward, thanks for pointing out.

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [May 29, 2026, 2:38pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/4 "2026-05-29T14:38:04Z")

</div>

I would make H checks \> 24 and M checks \> 59.  
I also would make good use of the ternary operator (there is even a compound situation in your code. This is the classroom textbook example of one use of ternary.  
Conceptually,

```arduino
 hour = (hour > 24) ? 1 : (now.hour() + 1);

```

Even that code can be simplified but I will leave that to you.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [May 29, 2026, 2:58pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/5 "2026-05-29T14:58:43Z")

</div>

Start the loop() like this... so you have `minute` and `hour`

```arduino
void loop() {
  DateTime now = rtc.now();
  minute = now.minute();
  hour = now.hour();
  .
  .
}

```

[edit]

Here is a minimal sketch for your digit isolation sketch...

```arduino
#include <RTClib.h>
RTC_DS3231 rtc;
uint8_t digits[4]; // four element array

void setup() {
  Serial.begin(115200);
  rtc.begin();
  // rtc.adjust(DateTime(F( __DATE__ ), F( __TIME__ ))); // set sketch "compile" time
  // rtc.adjust(DateTime(2021, 1, 21, 3, 45, 0)); // set manual time January 21, 2021 at 3:45.0 am
}

void loop () {
  DateTime now = rtc.now();
  uint8_t hour = now.hour();
  uint8_t minute = now.minute();

  digits[1] = ((hour / 10) % 10); //formula for the first digit
  digits[2] = (hour % 10); //formula for the second digit
  digits[3] = ((minute / 10) % 10); //formula for the third digit
  digits[4] = (minute % 10); //formula for the fourth digit

  for (int i = 1; i < 5; i++) {
    Serial.print(digits[i]);
    Serial.print(" ");
  }
  Serial.println();
  delay(1000); // replace delay() with millis() timer
}

```

I assume your button-pushing is to adjust the (H)our and (M)inute...

- monitor each button for "WAS PRESSED" (read about button debounce)
- add "1" to the element (hour or minute)
- check for rollover ( ~~9 \>\> 0,~~ 12 \>\> 1 and 59 \>\> 0)
- call `rtc.adjust();` with the new time.

---

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [May 29, 2026, 3:30pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/6 "2026-05-29T15:30:01Z")

</div>

Yes but the thing is once I increment hour or minute or hour, the number will imidiately revert back.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [May 29, 2026, 3:32pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/7 "2026-05-29T15:32:37Z")

</div>

> [@old\_ornstein](#):
>
> number will imidiately revert back.

The numbers will be exactly the result of `rtc.now();`... so you need to `rtc.adjust();` after you change the hour/minute.

---

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [May 29, 2026, 4:15pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/8 "2026-05-29T16:15:13Z")

</div>

I have been thinking. What is "i" in this scenario for?

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [May 29, 2026, 4:23pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/9 "2026-05-29T16:23:41Z")

</div>

> [@old\_ornstein](#):
>
> What is "i"

Be more descriptive, like "copy quote" to show your reference...

Do you mean here?

```arduino
  for (int i = 1; i < 5; i++) {
    Serial.print(digits[i]);
    Serial.print(" ");
  }

```

If so, "`i`" is just a counter from 1 to 4, to count through the elements of your `digits[]` array.

---

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [May 29, 2026, 4:35pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/10 "2026-05-29T16:35:34Z")

</div>

Yes, that is exactly what I meant. Sorry for not being more descriptive with what I wanted. So the purpose of this is just to let you know how many digits there are?

```arduino
 for (int i = 1; i < 5; i++) {
    Serial.print(digits[i]);
    Serial.print(" ");
  }

```

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [May 29, 2026, 4:39pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/11 "2026-05-29T16:39:39Z")

</div>

> [@old\_ornstein](#):
>
> purpose of this

The first line counts from 1 to 4 (not 5... see the "less than" "\<" sign)

The second line prints an element from your `digits[]` array... so when "`i`" increases, so does the element number to be printed from `digits[element]`

The third line is just to put a separator between the elements (a "space").

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [May 29, 2026, 5:38pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/12 "2026-05-29T17:38:08Z")

</div>

> [@old\_ornstein](#):
>
> So the purpose of this is just to let you know how many digits there are?

It's the "index" of the `for()` loop, a subject that's worth your time to research.

---

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [June 15, 2026, 9:49am UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/13 "2026-06-15T09:49:36Z")

</div>

Very late reply, but how do you actually use rtc.adjust()? Especially in the scenario you mentioned.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [June 15, 2026, 12:49pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/14 "2026-06-15T12:49:29Z")

</div>

> [@old\_ornstein](#):
>
> use rtc.adjust()?

Post #5 shows these two lines...

```arduino
  // rtc.adjust(DateTime(F( __DATE__ ), F( __TIME__ ))); // set sketch "compile" time
  // rtc.adjust(DateTime(2021, 1, 21, 3, 45, 0)); // set manual time January 21, 2021 at 3:45.0 am
}

```

Un-comment one of these lines and upload the sketch.

Then, re-comment the line and upload again.

This is to say: run `rtc.adjust()` one time, then remove it. The RTC battery will allow the RTC to keep time until the battery dies.

---

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [June 16, 2026, 7:13am UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/15 "2026-06-16T07:13:27Z")

</div>

No what I meant is in your first post. In the first post, at the part where you instructed me how to adjust the time, you mentioned calling rtc.adjust(); to have the time adjusted permanetly. How does that works? rtc.adjust(); I always ask me to put a value inside it, I can't just drop it at the end by itself.

---

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [June 16, 2026, 8:07am UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/16 "2026-06-16T08:07:56Z")

</div>

This is the best I can come up with based on your instruction

```arduino
//this version is working, don't change it. Make a copy instead.
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_GenericDevice.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Adafruit_SPIDevice.h>
//renember to include the entire Adafruit BusIO library, the original <Adafruit_I2CRegister.h> library is missing for some reason
#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.
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 = LOW;
int lastmbstate = LOW;
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.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 == HIGH) {
        if (hour == 24){
          hour = 0;
          rtc.adjust(hour);
        }
        else {
          hour ++;
          rtc.adjust(hour);
        }
      }
    }
  }
  if (mreading != lastmbstate) {
    lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (mreading != mbstate) {
      mbstate = mreading;
      if (mbstate == HIGH) {
        if (minute == 60){
          minute = 0;
          rtc.adjust(minute);
        }
        else {
          minute ++;
          rtc.adjust(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);
   
}

```

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [June 16, 2026, 9:57am UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/17 "2026-06-16T09:57:01Z")

</div>

When using rtc.adjust(), you need to provide the full data and time. In the case of adjusting the hour, just take the current data/time you have read from the RTC and only change the hour:

```arduino
          rtc.adjust(DateTime(now.year(), now.month(), now.day(), hour, now.minute(), now.second()));
```

When adjusting the minute, take the hour from the RTC, and only change the minute. You could also set the second to zero when adjusting minutes, so that you can control more precisely when the clock advances to the next minute.

---

<div class="post-metadata">

**Author:** ![old\_ornstein](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/old_ornstein/32/1273044_2.png) [@old\_ornstein](https://forum.arduino.cc/u/old_ornstein)\
**Post date:** [June 16, 2026, 4:58pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/18 "2026-06-16T16:58:01Z")

</div>

Ok so I got this. It doesn't give me errors anymore but it still doesn't work as intended.

```arduino
//this version is working, don't change it. Make a copy instead.
//yo I am goated
#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
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 + 1;
          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 + 1;
          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);
   
}

```

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [June 16, 2026, 7:54pm UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/19 "2026-06-16T19:54:46Z")

</div>

> [@old\_ornstein](#):
>
> doesn't work as intended

Describe the sequence of events when your sketch "does not work", then describe how you intended your sketch to work.

---

<div class="post-metadata">

**Author:** ![HazardsMind](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hazardsmind/32/215209_2.png) [@HazardsMind](https://forum.arduino.cc/u/HazardsMind)\
**Post date:** [June 17, 2026, 12:25am UTC](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319/20 "2026-06-17T00:25:55Z")

</div>

This compiles but I don't have the hardware to test it.

```arduino
//this version is working, don't change it. Make a copy instead.
//yo I am goated
#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
  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;
        } else {
          hour += 1;
        }
      }
    }
  }

  if (mreading != lastmbstate) {
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (mreading != mbstate) {
      mbstate = mreading;
      if (mbstate == 1) {
        if (minute == 60) {
          minute = 0;
        } else {
          minute += 1;
        }
      }
    }
  }

  rtc.adjust(DateTime(F( __DATE__ ), hour, minute, now.second())); // Update the hours and minutes

  // 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);
}

```

[Next page](https://forum.arduino.cc/t/need-help-adjusting-time-on-seven-segment-display-clock/1446319.md?page=2)
