Accelstepper delay without delay

Hi guys, i am a noob at this, but i am trying a simple project.

i have two steppers, a smaller one is attached to the shaft of the larger one, the larger one turns the smaller motor to two different angles, when its over a certain angle the smaller one spins.
i am trying to add a delay to each of the larger ones end points, which i will control with a potentiometer, for now i just need to get it working.
I need to use millis() instead of delay so i can run the smaller one on and off.
If someone could point me in the right direction that would be great.

#include <AccelStepper.h>

long previousTime = 0;
long delaywait = 0;

AccelStepper stepDrive(1, 10, 11);    //Head Motor
AccelStepper glassDrive(1, 5, 6);     //Glass motor



void setup() {
  stepDrive.setMaxSpeed(300);
  stepDrive.setAcceleration(20000);
  stepDrive.setCurrentPosition(0); 
  
  glassDrive.setMaxSpeed(200);
  glassDrive.setAcceleration(20000);
  glassDrive.setCurrentPosition(0);
  glassDrive.setSpeed(2000);
}




void loop() {
  
  unsigned long currentMillis = millis();
  
  
  
  if (stepDrive.currentPosition() == 0)        //send head drive to 300
        {   
          stepDrive.moveTo(300);                  
        }
        
  if (stepDrive.currentPosition() == 300 )     //send head drive back to load
        {
              int newtime = currentMillis + (1000);            // THIS IS THE UNKNOWN BIT I WANT IT TO DELAY FOR 1s BEFORE RETURNING
                    if (currentMillis == newtime) 
                    
                    {
                      stepDrive.moveTo(0);
                    }
       }
       
       
       
      if(stepDrive.currentPosition() > 150)      //spool motor up as it passes 150
       {
         glassDrive.runSpeed();
       }
       
        
        stepDrive.run();
}

The demo several things at a time illustrates how to use millis(). It is important always to use subtraction when testing the time interval.

I think you need to reconsider how your program is organized.

It sounds like there are different states - for example
stepper A is moving
stepper A is waiting
stepper B is moving etc.

Use a variable (or 2) to keep track of what state your system is in.

If you write down a list of the states in the style I have used it should become clearer how to manage the timing of events. Perhaps a timer should be started when a state changes.

Have a look at planning and implementing a program.

You may also find some useful stuff in stepper motor basics

...R

millis() isn't too tricky to figure out.
in general it is

  1. Capture current millis() value in a variable. Done once, and usually in a conditional statement
    and not at the beginning of Loop{}. Or else every loop it will be captured.

condition{
unsigned long capturedMillisTime = millis();
}

  1. When you do your check, compare millis() to that time. If the difference is greater than a value, that much time has passed.

if ((millis() - capturedMillisTime) > yourTime){
do your thing;
}

From there, you can alter when you update your captured time as your code grows.

Edit: keyword

ApexM0Eng:
condition{
long capturedMillisTime = millis();
}

Always use unsigned long for values associated with millis()

...R