So, I don't know a lot but I know I've got quite an education reading this forum and I'm grateful for it.
I'm trying to figure out how to insert a delay in this code so when the switch is tripped, the motor will pause before starting in the opposite direction. Right now, the gantry bounces between the switches (which is fun but I need a delay at the end of each stroke).
I have my Arduino Uno and Big Easy Driver connected to a Mercury Motor SM-42BYG011-25 with a Step Angle 1.8*, 12V, 2Phase, .33A.
#define stepPin 2
#define dirPin 3
#define pinLimitswitchLeft 4 // these can be either left or right depending on motor wiring and dir pin.
#define pinLimitswitchRight 5 // these switches must be N.O. types
int stepDelay = 100; // this is the step delay in microseconds. Reduce this to speed up motor rotation and vice versa.
pinMode (stepPin, OUTPUT);
pinMode (dirPin, OUTPUT);
pinMode (pinLimitswitchLeft, INPUT_PULLUP);
pinMode (pinLimitswitchRight, INPUT_PULLUP);
digitalWrite(dirPin, HIGH); // set direction pin, the direction that the motor will rotate is dictated by it's wiring
while (digitalRead(pinLimitswitchLeft) == HIGH) // move motor until left limit switch is pressed.
digitalWrite(dirPin, LOW); // set direction pin, the direction that the motor will rotate is dictated by it's wiring
while (digitalRead(pinLimitswitchRight) == HIGH) // move motor until right limit switch is pressed.