AccelStepper smooth faster/slower speed while running

Hello,

I managed to modify the speed every ~x sec while running with this code :

#include <AccelStepper.h>

#define MotorInterfaceType 4

AccelStepper stepper = AccelStepper(MotorInterfaceType, 0, 2, 1, 3);

unsigned long previousMillis = 0;
int interval = 1200;

void setup()
{ 
  stepper.setAcceleration(50);
}

void loop()
{

  unsigned long currentMillis = millis();
  if 
  (currentMillis - previousMillis >= interval) {
  previousMillis = currentMillis;

  stepper.setMaxSpeed(random(100,860));   
  stepper.move(6000);
  interval = random(2000,5050);
  }
  stepper.run();
 
        
  

}

But It is not fluid as I would like it to be.

If it does have to go faster, the acceleration is working. But if it does have to slow, It slows down roughly.

Any idea how I could get the speed smoothly slow down ?

how can you tell if you are randomly setting the speed and the time between changes in speed?

I think this is because max speed is not supposed to change while a motor is moving.

Maybe use setSpeed() to change speed, and runSpeed() rather than run()

Didnt work out, maybe someone could help me with a fading system or something ? smooth increment instead of changing the speed directly

It is not very difficult to write your own acceleration code without needing the library. Simple acceleration code.

...R