been trying to control a stepper motor

i am trying to control a stepper motor via BT but I am trying to make it so if i input "1" the motor will continue moveing until i change value to 0.

it is not working like i want it too now cause when ever i press 1 it spins then stops and waits for a value.

what are you guy's suggestions?


#include <Stepper.h>
#define STEPS 200
Stepper stepper(STEPS, 4, 5, 6, 7);

int value_bluetooth = 0;

void setup()
{
Serial.begin(9600);
Serial.println("Stepper test!");
// set the speed of the motor to 30 RPMs
stepper.setSpeed(60);
}

void loop()

{ if (value_bluetooth==0) {
Serial.println("enter value: ");

while (Serial.available()==0){
}
value_bluetooth = Serial.parseInt();
Serial.println( value_bluetooth );
delay (1000);
}
{
if (value_bluetooth== 1 ) {
Serial.println("forward");
stepper.step(STEPS);
value_bluetooth = 0;
}
delay (1000);}

if (value_bluetooth== 2 ) {
Serial.println("backward");
stepper.step(-STEPS);
value_bluetooth = 0;
}
delay (1000);
{
if (value_bluetooth== 0 ){
Serial.println("stop");
stepper.step(0);
}

}
}

If you want a responsive program you MUST get rid of ALL the delay()s as they block the Arduino from doing other things.

Have a look at how millis() is used to manage timing without blocking in Several things at a time

Also have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

If you want the motor to keep moving indefinitely it is probably easiest to get it do to a series of single steps. So save the value received from the BT module and if that saved value is '1' make a step.

...R
Stepper Motor Basics
Simple Stepper Code

Using Tools + Auto Format would show that you have a lot of useless curly braces.

You need to separate the getting of data from the serial port from the using that data.

If you want the stepper to continue stepping until you send another value, you need to stop changing the value of value_bluetooth except when the change is because there is data to read.