Start/Stop/Restart Loop with Button Press

Hi all,

Been using this site as a reference for my projects for awhile now and thought I’d try to get some help with a problem I have. I have a loop that turns on a set of Stepper Motor Sequences and I’m trying to include 3 buttons: Restart, Pause, Resume so that one button will restart the loop, one button will pause the loop and one button will resume the loop. I figured out how to have the loop start at the push of a button and I included the code below. Any takers?

int myCounter = 0;
int mySwitchPin = 4;

void setup() {
pinMode(mySwitchPin, INPUT_PULLUP);
}

void loop() {
if(myCounter<5) {
doSomething();
myCounter = myCounter + 1;
}
else if(digitalRead(mySwitchPin) == LOW) {
myCounter = 0;
}
}

doSomething();

Post the doSomething() function. What it does and how it does it is crucial to answering your question

Does the stepper step() function block code execution until it is complete ?

Examine the topic discussed here.

Program your switch where a short push is a toggle, i.e. pause/continue.

Long press is a restart.