Slider dc motor doomed?

It's been a couple of days but I've been working on a camera slider. A lot of sliders I see just pan back and forth continuously. I am trying get my motor to go forward when I press a button, and then go back when I push the button again. The problem I have is since it is a void loop, even if I command it to stop and even disengage the pin, the program will just loop and go forward again after the delay has finished. I googled and found to use while(1) but that would create an infinite loop that would no longer check for button state changes. This is my last step and it's killing me lol, am I doomed to have pecan pie way to stop it until the next button press?

Edit* I just thought of something, when the program is watching for button state changes, if buttonstate == 2 then it is forced to do that until the next change, so is there a way that I could say if buttonstate == 2 then go forward for 4 seconds then button counter++, from there I could say if buttonstate == 3 then delay(5000) this way the motor would move and then check every 5 seconds for a state change...idk this is just all theoretical

Why don't you post the code so we can help you with it.

Edit* I just thought of something

Too bad it wasn't posting your code.

PaulS:
Too bad it wasn’t posting your code.

Delta_G:
Why don’t you post the code so we can help you with it.

Yea I will when I get home, when i’m at school I just do the logical steps so when I get home I can hit the ground running, if I had my IDE with me, I would just try this out myself instead of asking without trial and error :slight_smile: I’ll post it later if it doesn’t work

So, your slider can be in four states:

"I am moving forward" "I am moving back" "I am stopped, but next time I move I should move forward" "I am stopped, but next time I move I should move back"

boolean the_current_direction_is_left;
boolean the_button_was_down_last_time_I_looked;

loop() {
  if(the button is down now) {
    move in the current direction;
    the_button_was_down_last_time_I_looked = true;
  }
  else 
  // button is up now, so
  if(the_button_was_down_last_time_I_looked){
    the_current_direction_is_left = !the_current_direction_is_left;
    the_button_was_down_last_time_I_looked = false;
  }
}

resistorswtf: Yea I will when I get home, when i'm at school I just do the logical steps so when I get home I can hit the ground running, if I had my IDE with me, I would just try this out myself instead of asking without trial and error :) I'll post it later if it doesn't work

Please do the testing yourself before wasting your time and ours.

You would not go into a bank and say "what do you recommend for a good investment? I'm hoping to win the lottery next Saturday?"

...R