Help controlling multiple stepper motors with one button.

I'm trying to get my button to turn my stepper motor with 10 presses of the button before switching to the next stepper motor. I have my code sorted to turn a single stepper motor to the correct degrees but unsure on how I get the button to switch to the next stepper motor can complete the same task as stepper one.

Any help much appreciated.

Code for single stepper motor below.

#include <Stepper.h>

const int buttonPin = 2;
const int stepsPerRevolution = 208;

Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

int buttonState;
int lastButtonState = LOW;

unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 100;

void setup() {
pinMode(buttonPin, INPUT);

myStepper.setSpeed(50);

digitalWrite; Serial.begin(9600);
}

void loop() {
int reading = digitalRead(buttonPin);

if (reading != lastButtonState) {

lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {

if (reading != buttonState) {
buttonState = reading;

if (buttonState == HIGH) {
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
}
}
}

lastButtonState = reading;
}

tony_worby:
I'm trying to get my button to turn my stepper motor with 10 presses of the button before switching

IMHO that is a recipe for user frustration. Most of the time the user will get the number of presses wrong.

Use more buttons.

...R

Learn about state-machines and how to draw state transition diagrams - this is the basis for a lot
of UI input gesture parsing. For instance double-click detection, long press v. short press, etc.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.