hey, guys thanks for your support I have some issues with my code I was controlling a 2stepper motor with a limit switch but I want a delay between the two motors starting when one of the limit switches is pressed wait for the delay and start am trying to insert the delay function but the stepper step per revolution is decreased how can I fix this code.
// Declare Stepper Motor used pins
#define dirPin1 12 // stepper one
#define stepPin1 13
#define stepPin2 11 // stepper two
#define dirPin2 10
const int limit1 = 23;// limit switch of cover open
const int limit2 = 24;// limit switch of cover close
void setup() {
// Set up stepper motor
pinMode(stepPin1, OUTPUT);
pinMode(dirPin1, OUTPUT);
//Set up 2 limit switches as input pull-down
pinMode(limit1 , INPUT);
pinMode(limit2 , INPUT);
}
void loop()
{
if (digitalRead(limit1) == LOW) // when limit switch one is not pressed
{
digitalWrite(dirPin1, HIGH); // stepper motor turns clock wise
digitalWrite(stepPin1, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin1, LOW);
}
else {
digitalRead (limit1 == HIGH); // when the limit switch one is pressed
digitalWrite(stepPin1, LOW); // turn off stepper motor one
}
if (digitalRead(limit1) == HIGH) // when limit one is pressed
{
if (digitalRead(limit2) == LOW) // when limit two is not pressed
{
digitalWrite(dirPin2, LOW); // stepper motor two turn anti clock wise
digitalWrite(stepPin2 , HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin2 , LOW);
}
}
else {
digitalRead(limit1 == LOW); // when limit one is pressed
digitalRead(limit2 == HIGH); // when limit two is pressed
digitalWrite(stepPin2, LOW); // turn off stepper two