#define EN 8 //Negative Enable pin #define X_DIR 5 //Direction pin #define X_STP 2 //Step pin #define SWITCH1Pin A5 //A5 is the pin of the first switch #define SWITCH2Pin A4 //A5 is the pin of the second switch int delayTime=80; //Delay between each pause (uS) int stps=6400;// Steps to move microsteps 1/32 (200*32 = 6400) void step(boolean dir, byte dirPin, byte stepperPin, int steps) { digitalWrite(dirPin, dir); // for (int i = 0; i < steps; i++) { digitalWrite(stepperPin, HIGH); delayMicroseconds(delayTime); digitalWrite(stepperPin, LOW); delayMicroseconds(delayTime); } } void setup(){ pinMode(X_DIR, OUTPUT); //direction pin = output pinMode(X_STP, OUTPUT); //step pin = output pinMode(EN, OUTPUT); //negative enable pin =output digitalWrite(EN, LOW); //start negative enable pin at low pinMode(SWITCH1Pin, INPUT_PULLUP); //Set switch to input pullup pinMode(SWITCH2Pin, INPUT_PULLUP); //Set switch to input pullup } void loop(){ step(true, X_DIR, X_STP, 3200); //true equals back towards motor delay(2000); }