C++:
#include <Stepper.h>
long previousMillis = 0;
int ledState=LOW;
int buttonState=LOW;
int button = 14;
int led = 13;
const int stepsPerRevolution = 64;
Stepper myStepper1(stepsPerRevolution, 8,9,10,11);
Stepper myStepper2(stepsPerRevolution, 4,5,6,7);
void setup() {
myStepper1.setSpeed(20);
myStepper2.setSpeed(20);
pinMode(led, OUTPUT);
pinMode(button,INPUT);
}
void loop()
{
unsigned long currentMillis = millis();
if(buttonState==LOW&&digitalRead(button)==HIGH){
buttonState=!buttonState;
if (buttonState==HIGH){
if(currentMillis-previousMillis>1000){
previousMillis = currentMillis;
digitalWrite(led,buttonState);
}
myStepper1.step(100);
myStepper2.step(100);
myStepper2.step(-100);
}
else {
buttonState=LOW;
}
}
else {
digitalWrite(led,LOW);
}
}