The display does not show data at a certain stage

Hi, I made a wire and cable cutter some time ago. Now I have decided to raise the whole project a little higher and teach the cutter to strip as well.

But after I turned on the cutter, the display did not work. The 16x2 line display was originally fitted. Since I didn’t have any other at home, I decided to replace it with a display from the Nokia 5110. The whole program was modified to use this display, using adafruit, and the adafruit GFX library.

Well, the wire cutter works as it should. But at some stage the display stops showing data. I thought I just couldn’t catch up with the microcontroller, so I added a delay to the program. But it did not help.

This is how it all works. The basis is the home screen, after clicking on the next screen I set the length of the cut, for the next number of pieces, for the next number of repeated, the next one will show me a recap, for example: 102mm x 25pcs x 2x. After pressing the confirmation print, the wire cutting overview should be displayed. And here is the problem, this screen does not pop up, the program runs normally, cuts the wires, in the required length and amount. And when finished, the final screen will appear informing me that the cutting has been completed.

This is the part of the code:

void currentlyCutting(void) {
    display.setTextSize(fontSize);
    display.setTextColor(BLACK);
    display.setCursor(0, 0);
    display.println((String)0 + "/" + (String)wireQuantity);
    display.setCursor(0, 8);
    display.println("???s");
    delay(100);
    int stepsToTake = (int)wireLength/mmPerStep;
    for(int i = 0; i < wireQuantity; i++) {
      unsigned long timeForOneCycle = millis();
      digitalWrite(dirPin, HIGH);
      for(int x = 0; x < stepsToTake; x++) {
        digitalWrite(stepPin, HIGH);
        delay(100);
        digitalWrite(stepPin, LOW);
        delay(100);
      }

      display.setCursor(0, 0);
      display.println((String)(i+1)+ "/" + (String)wireQuantity);
      delay(100);
      snippers.write(closedAngle);
      delay(600);
      snippers.write(openAngle);
      delay(600);

      display.setCursor(0, 8);

      unsigned long timeRemaining = ((millis() - timeForOneCycle)*(wireQuantity - (i+1)))/1000;
      display.println((String)timeRemaining + "s   ");
      delay(100);      
    }
    wireLength = 0;
    wireQuantity = 0;
    state = 5;
}

Switching between screens works as follows:

if (!digitalRead(rightButton)){
    if(state == 5){
      state = 0;
    }
    else{
      state += 1;
    }
    delay(200);
    display.clearDisplay();
  }
  if (!digitalRead(leftButton) && state > 0 && state < 4){
    state -=1;
    delay(200);
    display.clearDisplay();
  }
  
  switch (state){
    case 0:
      homeScreen();
      break;
    case 1:
       chooseWireLength();
       break;
    case 2:
      chooseWireQuantity();
      break;
    case 3:
      confirm();
      break;
    case 4:
      currentlyCutting();
      break;
    case 5:
      finishedCutting();
      break;
  }

Compared to the original code, there was only a change in the display and modification of the drawUI () function, which originally displayed only tex previous and next. Now this feature shows an arrow to the right and left, because with the text the display looked overprinted. And that’s why I use the GFX library. The code was originally based on a project I was inspired by on the internet, but everything worked with the original display

So the problem is solved. I sat on the problem for several hours and did not realize that the solution is simple, namely to turn off the display buffer at the end of each cycle