#include <Button.h>
#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 200
Button button1(4);
const int stepDelay = 2000;
const int ledPin = 13;
void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
button1.begin();
}
void loop() {
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
if (button1.pressed()){
for (int i = 0; i < 200; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
delay(500);
digitalWrite(dirPin, LOW);
for (int i = 0; i < 200; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
}