UKHeliBob:
Save the millis() value at the time that you start the stepper. Then, each time through loop(), check whether the required period has elapsed by subtracting the start time from the millis() value now. If the period has elapsed then act accordingly and maybe save the start time for the next activity. If not, then go round loop() again, perhaps taking other actions and/or reading inputs, but don't block the free running of loop().
Look at the BlinkWithoutDelay example in the IDE and Several things at the same time
Thanks UKHeliBob!
So I started again from scratch to the simple code that just gets the motor started and runs continuously. I tried added the millis command, but now the motor doesn't move. Any suggestions as to what I should add or remove in my code?
If I leave the interval at 1000 which I believe is a second nothing happens. If I set it to 0 the stepper runs continuously.
Heres the code I am trying now:
#include "DualMC33926MotorShield.h"
int motorDirPin = 2;
int motorStepPin = 3;
unsigned long interval=1000;
unsigned long previousMillis=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if ((unsigned long)(millis() - previousMillis) >= interval) {
previousMillis = millis();
digitalWrite(3, !digitalRead(3));
digitalWrite(3, HIGH);
delayMicroseconds(35);
digitalWrite(3, LOW);
delayMicroseconds(10);
} }