const int relayPin = 8; // relay control pin
const int footSwitchPin = 2; // foot switch input pin
const int dirPin = 9; // DIR control pin for microstepping driver
const int enablePin = 10; // ENABLE control pin for microstepping driver
const int stepPin = 11; // STEP control pin for microstepping driver
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(footSwitchPin, INPUT);
pinMode(dirPin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(stepPin, OUTPUT);
}
void loop() {
// read the foot switch input
int footSwitchState = digitalRead(footSwitchPin);
// if the foot switch is pressed, switch to the microstepping driver and run the stepper motor continuously
if (footSwitchState == HIGH) {
digitalWrite(relayPin, LOW); // turn on the relay
digitalWrite(enablePin, HIGH); // enable the microstepping driver
digitalWrite(dirPin, LOW); // set the DIR pin to control the direction of the stepper motor
while (true) {
// send step and direction signals to the microstepping driver
digitalWrite(stepPin, HIGH);
delayMicroseconds(100);
digitalWrite(stepPin, LOW);
delayMicroseconds(100);
}
}
// if the foot switch is not pressed, switch to the other driver
else {
digitalWrite(relayPin, HIGH); // turn off the relay
digitalWrite(enablePin, LOW); // disable the microstepping driver
}
}