I did try that, after a lot of trial and error I managed to workout a timer but the code does not work well in the loop as it becomes extremely slow.
The stepper library can not move the motor in the setup where the homing takes place either, so that is not going to work?
I wrote this sketch to test it before I add it to the main sketch and it works well as is:
//Include the Stepper library
#include <AccelStepper.h>
// Time periods between steps in milliseconds
const unsigned long Stepinterval =1;
const int solenoidPin = 53; //This is the solenoid output pin
const int home_switch = 52; // Pin 52 connected to Homing Switch (Sensor)
const byte stepPin = 2;
const byte dirPin = 5;
const byte enablePin = 8;
int StopHoming = 0;
// Variable holding the timer value so far.
unsigned long Steptimer;
AccelStepper x_stepper(AccelStepper::DRIVER, stepPin, dirPin);
void setup ()
{
Serial.begin(9600);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
pinMode(solenoidPin, OUTPUT);
Steptimer = millis ();
} // end of setup
void MoveStepper ()
{
digitalWrite(dirPin, HIGH);
if (digitalRead (stepPin) == HIGH)
digitalWrite (stepPin, LOW);
else
digitalWrite (stepPin, HIGH);
Steptimer = millis ();
} // end of MoveStepper
void loop ()
{
if (!digitalRead(home_switch)==LOW){
if ( (millis () - Steptimer) >= Stepinterval){
MoveStepper ();
}
}
} // end of loop
But if I add it to my main sketch it's just extremely slow and has to run through the loop the whole time. It seems with controlling the motor and trying to home it there just is no alternative then delay() ?