so I am fairly new to all this, but what I am trying to do is have a stepper motor run continuously in 1 direction until I press 1 of 2 buttons. 1 button to speed up in same direction and another to speed up in reverse. The motor is running a clock, but want 2 buttons (forward and reverse) to increase speed for setting time. I got the buttons working but when I add this
myStepper.setSpeed(1);
myStepper.step(-stepsPerRevolution);
delay(0);
to the bottom for continuous running, the buttons no longer work. But the continuous runs fine. Not sure what I am missing here. I tried putting this at the top of the void loop also tried putting it in the setup still the same.
thanks
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
const int buttonPin = 2; // the number of the pushbutton pin
const int buttonPin2 = 4; // the number of pushbutton2 pin
// variables will change:
int buttonState = HIGH; // variable for reading the pushbutton status
int buttonState2 = HIGH;
// initialize the stepper library on pins 9 through 12:
Stepper myStepper(stepsPerRevolution, 9, 10, 11, 12);
void setup() {
// set the speed at __ rpm:
myStepper.setSpeed(1);
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
// initialize the serial port:
//Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
if (buttonState == HIGH) {
// step one revolution in one direction:
//Serial.println("clockwise");
myStepper.setSpeed(100);
myStepper.step(stepsPerRevolution);
delay(0);
}
else if (buttonState2 == HIGH) {
// step one revolution in one direction:
//Serial.println("clockwise");
myStepper.setSpeed(100);
myStepper.step(-stepsPerRevolution);
delay(0);
}
myStepper.setSpeed(1);
myStepper.step(-stepsPerRevolution);
delay(0);
}