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?