// Define the Pins used
#define step_pin 5 // Pin 5 connected to Steps pin on EasyDriver
#define dir_pin 6 // Pin 6 connected to Direction pin
#define x_pin A0 // Pin A0 connected to joystick x axis pin
#define home_switch 9 // Pin 9 connected to Home Switch (MicroSwitch)
int direction; // Variable to set Rotation (CW-CCW) of the motor
int steps; // Used to set HOME position after Homing is completed
void setup() {
pinMode(dir_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(x_pin, INPUT);
pinMode(home_switch, INPUT_PULLUP);
delay(5); // Wait for EasyDriver wake up
// Start Homing procedure of Stepper Motor at startup
while (digitalRead(home_switch)) { // Do this until the switch is activated
digitalWrite(dir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(5); // Delay to slow down speed of Stepper
digitalWrite(step_pin, LOW);
delay(5);
}
while (!digitalRead(home_switch)) { // Do this until the switch is not activated
digitalWrite(dir_pin, LOW);
digitalWrite(step_pin, HIGH);
delay(10); // More delay to slow even more while moving away from switch
digitalWrite(step_pin, LOW);
delay(10);
}
steps=0; // Reset position variable to zero
}
void loop() {
}