My code suddenly stopped working

First of all, here is the code:

void DS1302Startup(bool changingTime){

    Rtc.Begin();
    if(changingTime == true){
      while(digitalRead(8) == LOW){
        Serial.println("test");
      }
        Serial.println("test2");
      bool hm;
      char HMS;
      while(1){
        
        n = digitalRead(encoder0PinA);
        if ((encoder0PinALast == HIGH) && (n == LOW)) {
          if (digitalRead(encoder0PinB) == HIGH) {
            if(hm == true){
              encoder0Pos2--;
              encoder0Pos = max(encoder0Pos2,0);
              encoder0Pos2 = encoder0Pos;
            }
            else{
              encoder1Pos2--;
              encoder1Pos = min(encoder1Pos2,0);
              encoder1Pos2 = encoder1Pos;
            }
          } else {
            if(hm == true){
              encoder0Pos2++;
              encoder0Pos = min(encoder0Pos2,24);
              encoder0Pos2 = encoder0Pos;
            }
            else{
              encoder1Pos2++;
              encoder1Pos = min(encoder1Pos2,59);
              encoder1Pos2 = encoder1Pos;
            }
          }
        }
        encoder0PinALast = n;
        HMS = char(sprintf(encoder0Pos, 2));
        HMS += ":";
        HMS += char(sprintf(encoder1Pos, 2));
        HMS += ":";
        HMS += "00";
            Serial.println(HMS);
        
        if(digitalRead(8) == LOW){
          milli = millis();
          while(digitalRead(8) == LOW){
            
          }
          if(millis() - milli <10){
            
          }
          else if(millis() - milli > 10 && millis() - milli < 2000){
            hm = !hm;
          }
          else if(millis() - milli > 2000){
            HMS = char(encoder0Pos);
            HMS += ":";
            HMS += char(encoder1Pos);
            HMS += ":";
            HMS += "00";
            break;
          }
        }
        FastLED.clear();
        displayTime(String(HMS), 0);
        FastLED.show();
      }
      RtcDateTime compiled = RtcDateTime("03 31 2020", char(HMS));
      Rtc.SetDateTime(compiled);
      
    }
}

That is, as you can see not the whole code. I'll put the file into the attechments because otherwise I would have to paste the whole 970 lines in here.

So, the Problem is that, if I start the program the bool changingTime equals true. Then the code starts the rtc clock and checks if changeTime equals true. If it equals true, it waits for the pushbutton to release. For that, I use a while loop that waits for the pushbutton to be released. As you can see, I've already putten Serial.println("test") into the while loop. The code still works fine and prints out test in the serial monitor as long as i hold down the pushbutton. After I stop pressing the pushbutton, Serial.println("test2") is not executed. But before i made some changes to the code, all worked fine. Sadly, I can't remember the changes.

BinarySecs.ino (261 Bytes)

DemoReel100_Uhr_Verstellen.ino (5.39 KB)

displayTime.ino (904 Bytes)

DS1302.ino (570 Bytes)

DS1302Startup.ino (2.06 KB)

NumberPatterns.ino (4.05 KB)

setNumber.ino (12.7 KB)

(deleted)

That's the Problem. I have buildt it half a year ago and had 2 versions on 2 differnt HDDs. The earlier version that worked on and that worked got destroyed together with my 1st HDD and my second HDD only has this version on it.

How is your button wired up? Are you sure it is going HIGH when you release it?

Yes, because the code leaves the while loop which means that the signal has to go high.

what exactly do you think this line

        HMS = char(sprintf(encoder0Pos, 2));

is doing?

It turns the number into a 2 digit number so:
1 -> 01
43 -> 43
and so on (the max value is 59).
Then it turns it into a char and adds it to the hms char.
In the end this should output a HH:MM:SS time value.

Two things that immediately stick out:

HMS is a single byte of storage

      char HMS;

sprintf() takes two char* as the first two arguments, a buffer to put the text into, and a format string to tell it what to put in the buffer, followed by however many arguments are needed by the format string. A number is not a valid 2nd argument.
~~ ~~int sprintf(char *__s, const char *__fmt, ...);~~ ~~

Apparently I'm wrong, although I don't quite understand why.
The error message the compiler is throwing out:

/homejd/Downloads/DemoReel100_Uhr_Verstellen/DS1302Startup.ino: In function 'void DS1302Startup(bool)':
/home/Downloads/DemoReel100_Uhr_Verstellen/DS1302Startup.ino:40:40: warning: invalid conversion from 'int' to 'char*' [-fpermissive]
       HMS = char(sprintf(encoder0Pos, 2));
                                        ^
In file included from /home/.arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino/Print.h:24:0,
                 from /home/.arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino/Stream.h:26,
                 from /home/.arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino/HardwareSerial.h:29,
                 from /home/.arduino15/packages/arduino/hardware/avr/1.8.2/cores/arduino/Arduino.h:233,
                 from /tmp/arduino_build_402151/sketch/DemoReel100_Uhr_Verstellen.ino.cpp:1:
/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/stdio.h:671:12: note:   initializing argument 1 of 'int sprintf(char*, const char*, ...)'
 extern int sprintf(char *__s, const char *__fmt, ...);

@ reply #7 6

No, it doesn't.

See man sprintf for correct syntax.

Westpol:
It turns the number into a 2 digit number so:
1 -> 01
43 -> 43
and so on (the max value is 59).
Then it turns it into a char and adds it to the hms char.
In the end this should output a HH:MM:SS time value.

Nope. Not even close...

char HMS[20];
sprintf(HMS, "%02i", encoder0Pos);
//...
// or if you have h, m, s variables
sprintf(HMS, "%02i:%02i:%02i", h, m, s);

Thanks for all the comments. I have rewritten the code and it all works fine now.