#include <Stepper.h>
#define LEDPIN 13
#define BUTTONPINSTART 2
#define BUTTONPINSTOP 3
uint32_t lastMillis;
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// put your setup code here, to run once:
pinMode(LEDPIN, OUTPUT);
pinMode(BUTTONPINSTART, INPUT_PULLUP);
pinMode(BUTTONPINSTOP, INPUT_PULLUP);
myStepper.setSpeed(1);
}
void loop() {
// put your main code here, to run repeatedly:
int buttonState = digitalRead(BUTTONPINSTART);
bool blinking = true;
if (buttonState == LOW) {
while (buttonState == LOW) {
buttonState = digitalRead(BUTTONPINSTART);
}
bool keepgoing = true;
while (keepgoing) {
int buttonState2 = digitalRead(BUTTONPINSTOP);
if (buttonState2 == LOW) {
while (buttonState2 == LOW) {
buttonState2 = digitalRead(BUTTONPINSTOP);
}
keepgoing = false;
}
if (millis() - lastMillis > 1000) {
lastMillis = millis();
if (blinking) {
digitalWrite(LEDPIN, HIGH);
}
else {
digitalWrite(LEDPIN, LOW);
}
myStepper.step(1);
blinking = !blinking;
}
}
digitalWrite(LEDPIN, LOW);
}
}