How can I pulse a stepper motor whilst also wanting to handle other tasks?
Instead of delaying between pulses, loop around the main loop() function as fast as possible constantly checking the time to see if we should pulse the motor.

This means that computations can occur in the loop (so long as they are reasonably fast).

To implement this, the micros() function can be used to get an unsigned long representing the microseconds that have passed since the start of the program.

Then in each loop cycle, we need to check if the difference between the current time and the last time that we pulsed is &gt;= the pulse delay. In which case, we send a pulse to the motor

However, instead of setting the last pulse time variable to the current time, we instead increment the last pulse variable by the delay time. This has the affect that even if we were slightly late in pulsing, we pretend that we did in fact pulse at the right time so that they do not drift over time.

This would look something like:

#define STEP_PIN  3
#define DELAY     100

uint32_t last_pulse;

void setup(){
    pinMode(STEP_PIN, OUTPUT);
    last_pulse = micros();
}

void loop(){
    //heavy computation taking time
    if (micros() - last_pulse &gt;= DELAY){
        last_pulse += DELAY;
        digitalWrite(STEP_PIN, LOW);
        digitalWrite(STEP_PIN, HIGH);
    }
}




Note that there is a slight subtlety here in that the result from micros() and therefore the value of last_pulse will overflow after ~70 minutes. However, because we are taking a difference of two unsigned numbers, this method will still work, so long as micros() is never a whole cycle ahead of last_pulse which in practice will never be the case.