Step Motor Control with push button

Hi this is my program. How can i change this program that step motor continuous going one way till I press button to other direction.

 #include <Stepper.h>

int forward = 2;
int reverse = 3;

Stepper motor(100, 10,11,12,13);            

void setup() {
  pinMode(forward,INPUT);
  pinMode(reverse,INPUT);
    Serial.begin(9600);
}

void loop() {
  int Speed = analogRead(A0);
  int RPM = map(Speed, 0, 1023, 0, 150);
  int f = digitalRead(forward);
  int r = digitalRead(reverse);
  if(f == 1 && r == 0 && RPM > 1){
  motor.step(1);
    motor.setSpeed(RPM);
    delay(.01);
  }
  if(r == 1 && f == 0  && RPM > 1){
    motor.step(-1);
    motor.setSpeed(RPM);
        delay(.01);
  }
  delay(5);
    Serial.println(RPM);
}

This is wrong.

delay(0.01);

delay() needs an integer value that is the number of milliseconds for the delay(). What you have will be treated as delay(0). And I suspect that you should not have any delay().

You have not told us what the code does at the moment.

If you want to make the motor move with a single button push you need a variable to record whether the motion is forward or reverse. And you need to arrange for your button to change the value of that variable. Have a look at the state-change examples in the Arduino IDE.

You may also find some useful stuff in Planning and Implementing a Program

...R

I want to make the motor move with a single button push.
Any idea?

mindaugas27:
I want to make the motor move with a single button push.
Any idea?

Yes. See the 3rd paragraph of Reply #1.

If you don't understand something I wrote please say what it is that you don't understand.

...R