Hello, I'm a little out of my depth here with the coding, my apologies for that. I am setting up a vertical positioning stage for a project that uses a stepper motor. What I want is for a 3-position switch to control the direction of motion, with up being up, down being down, and center being stop. I am having a lot of trouble trying to find a way to use a single pole on the stepper motor to hold the position in "stop mode".
Here is my schematic (sorry it's fritzing, but it's simple enough that it seems to make sense. If that's problematic feel free to let me know and I'll find another way)
Currently, this is the sketch I am using (yes, I know it's all wrong for this setup and the desired outcome)
// Define Pins
int reverseSwitch = 2; // push button for reverse
int driverPUL = 7; // PUL pin
int driverDIR = 6; // DIR pin
int spd = A0; // 10k pot
//vars
int pd = 500; // Pulse delay time
boolean setdir = LOW; // Set direction
// Interrupts
void revmotor() {
setdir = !setdir;
}
void setup() {
pinMode (driverPUL, OUTPUT);
pinMode (driverDIR, OUTPUT);
attachInterrupt(digitalPinToInterrupt(reverseSwitch), revmotor, FALLING);
}
void loop() {
pd = map((analogRead(spd)),0,1023,10000,500);
digitalWrite(driverDIR,setdir);
digitalWrite(driverPUL,HIGH);
delayMicroseconds(pd);
digitalWrite(driverPUL,LOW);
delayMicroseconds(pd);
}
My question is: how do I change this code from a reverse-direction switch to one that will read the value of A1 and respond to the different R values and no value at all? Should I be using a digital interrupt for this? If so, how do I set up a standstill state for the motor?

