Input numbers into serial number to output a function

Hey guys,

I am new to using Arduino and I have a code for a stepper motor. I have modified the same code in three different ways.

So the first code allows the motor to turn forward and back constantly, the second code has a 1 sec delay between the movements and the third code has a 5 second delay.

I want to set up a code where I input a number into the serial monitor e.g, 1 and it outputs the first code which is the motor running constantly, then if I input 2 it will run the code with the 1 second interval and so on....

This is the code I am using for the stepper motor at the moment, is anyone able to help me out?

Thanks!! :)

int Distance = 0; // Record the number of steps we've taken void setup() {

void setup() { pinMode(3, OUTPUT);

pinMode(4, OUTPUT);

digitalWrite(3, LOW);

digitalWrite(4, LOW);

}

void loop() {

digitalWrite(4, HIGH);

delayMicroseconds(1000);

digitalWrite(4, LOW);

delayMicroseconds(1000);

Distance = Distance + 4; // record this step // Check to see if we are at the end of our move

// two rotation for 1/8 bridge and 1 rotation for 1/6 bridge (for this code)

if (Distance == 3500) { // We are! Reverse direction (invert DIR signal)

if (digitalRead(3) == LOW) {

digitalWrite(3, HIGH); }

else {

digitalWrite(3, LOW);

} // Reset our distance back to zero since we're // starting a new move

Distance = 0; // Now pause for half a second delay(500);

} }

What have you tried?

Please read forum rules for posting code

You should start by looking for characters from Serial. Look at the built-in examples to see how.

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

...R