Running a stepper in parallel with using a touchscreen

Hey everyone, I am using the AccelStepper library to run a motor back and forth, while at the same time displaying some buttons and sensor readings on a 2.4 inch screen using the UTFT library. The code works fine if I separate the screen display function and the run function of the motor in different loops, but of course that means I can't use the screen while the motor is running. When I put both of them in the same loop, the motor stops working and it starts making rithmic sounds, like it wants to move but can't.

void loop() {
//Display

runDisplay();
  
//Stepper

 
  if(analogRead(SensorPin) < Limit){
  myStepper.setMaxSpeed(Speed1);
  myStepper.move(Pos);
  while(myStepper.distanceToGo() != 0){
  myStepper.run();
  runDisplay();
  }

    
  myStepper.setMaxSpeed(Speed2);
  myStepper.move(-Pos);
  while(myStepper.distanceToGo() != 0){
  myStepper.run();
  runDisplay();
  }
}

}

The runDisplay() function handles everything related to the screen. I tried including some run functions inside it, but it only made the motor make sounds at a faster frequency. As I said, if I remove the two runDisplay() functions from the while loops the motor works, but the screen stops updating. Any suggestions?

You need to post the complete program.

My guess is that the code for the display is slow and does not allow the run() function to be called often enough. It needs to be called more often (perhaps twice as often) as the rate at which steps are required.

If I am correct, maybe you can divide up the calls to the display so each individual call is short enough to allow the motor to run.

...R