const int stepPin = 3;
const int dirPin = 4;
const int swPin = 2;
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(swPin, INPUT_PULLUP);
digitalWrite(dirPin, LOW);
}
void loop() {
if (digitalRead(swPin) == LOW) {
digitalWrite(dirPin, HIGH); // CW
} else {
digitalWrite(dirPin, LOW); // CCW
}
// Один шаг
digitalWrite(stepPin, HIGH);
delayMicroseconds(800);
digitalWrite(stepPin, LOW);
delayMicroseconds(800);
}