The Arduino is controlling the stepper driver and it works but not quite as I’d want.
At the moment I have a speed control and a push button switch that changes the motor direction.
To stop the motor i’m using the ENABLE+ & ENABLE- terminals on the controler but this is not via the Arduino but rather directly.
What I’d like is to do is have a single 3 position switch (On-Off-On) that controls the direction and the enable functionality.
It would also help if a couple of LED’s were employed to show which position (Forward-Stop-Reverse) the switch was in.
Can anyone suggest how to code this?
(this is the sketch I’m using at the moment)
int reverseSwitch = 2; // Push button for reverse
int driverPUL = 7; // PUL- pin
int driverDIR = 6; // DIR- pin
int spd = A0; // Potentiometer
// Variables
int pd = 500; // Pulse Delay period
boolean setdir = LOW; // Set Direction
// Interrupt Handler
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,2000,50);
digitalWrite(driverDIR,setdir);
digitalWrite(driverPUL,HIGH);
delayMicroseconds(pd);
digitalWrite(driverPUL,LOW);
delayMicroseconds(pd);
}