I need to connect a 3 position momentary toggle switch to run a stepper motor in either forward or reverse. I have a TB600 driver and a NEMA23 stepper bipolar motor and a teensy 3.2 board. I'm not sure how to wire it or if this code will work, I can't seam to find a good example of this. Any help would be appreciated.
Code:
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
void setup() {
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
for(int x = 0; x < 800; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the direction of rotation
for(int x = 0; x < 800; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}