#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 9, 10, 11, 12);
// the previous reading from the analog input
int previous = 0;
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
// set the speed of the motor to 30 RPMs
stepper.setSpeed(150);
}
void loop() {
static unsigned long lastButtonTime = 0;
static boolean lastButtonState = false;
boolean newButtonState = digitalRead(buttonPin);
unsigned long currentTime = millis();
// Make sure it has been at least 100 milliseconds since the last button change to filter out bounces
if (newButtonState != lastButtonState && currentTime-lastButtonTime > 100)
lastButtonTime = currentTime;
lastButtonState = newButtonState;
if (newButtonState) { // Fresh button press
stepper.step(3000);
delay(4*1000); // Wait X seconds
stepper.step(-3000);
}
}
// change this to the number of steps on your motor
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 9, 10, 11, 12);
// the previous reading from the analog input
int previous = 0;
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
// set the speed of the motor to 30 RPMs
stepper.setSpeed(150);
}
void loop() {
static unsigned long lastButtonTime = 0;
static boolean lastButtonState = false;
boolean newButtonState = digitalRead(buttonPin);
unsigned long currentTime = millis();
// Make sure it has been at least 100 milliseconds since the last button change to filter out bounces
if (newButtonState != lastButtonState && currentTime-lastButtonTime > 100)
lastButtonTime = currentTime;
lastButtonState = newButtonState;
if (newButtonState) { // Fresh button press
stepper.step(3000);
delay(4*1000); // Wait X seconds
stepper.step(-3000);
}
}