How to control delay time and number of stepps in my program?

Hello, I have a problem. I need a program that receive a value (fot delay time) and a value for the number of steps. I have to move a step motor. Could you help me, please?
This is my program:

#include <Stepper.h> //Importamos la librería para controlar motores paso a paso

#define STEPS 200 //Ponemos el número de pasos que necesita para dar una vuelta. 200 en nuestro caso

// Ponemos nombre al motor, el número de pasos y los pins de control
Stepper stepper(STEPS, 8, 9, 10, 11); //Stepper nombre motor (número de pasos por vuelta, pins de control)

void setup()
{
 // Velocidad del motor en RPM
 stepper.setSpeed(2);
 Serial.begin(9600);
}

void loop()
{
 //char segundos = Serial.read();
 //int segundos;
 char cargas = Serial.read();
 int my=0;
 //char time = Serial.read();
 
 switch(cargas)
 {
   case '1':
   for(my=0;my!=1;my++)
   {
     stepper.step(2);  
     delay(1000);
   }
     break;
     
    case '2':
     for(my=0;my!=2;my++)
   {
     stepper.step(2);  
     delay(1000);
   }
     break;
     
     case '3':
     for(my=0;my!=3;my++)
   {
     stepper.step(2);  
     delay(1000);
   }
     break;
     case '4':
     for(my=0;my!=4;my++)
   {
     stepper.step(2);  
     delay(1000);
   }
     break;
     case '5':
     for(my=0;my!=5;my++)
   {
     stepper.step(2);  
     delay(1000);
   }
     break;
}
}

Please modify your post and put your code in code tags so it looks like this. Use the button like a scroll with <> on top of it. It makes it much easier to deal with.

Your code only reads one character from your PC which you seem to be using (in a very complicated way) to determine the number of steps. Why are you using a FOR loop when all you have to do is supply a different number as the parameter to stepper.step(numSteps)

What sort of value do you want to send to the Arduino to determine the delay time? For example if you just want to pick one of (say) 10 different delays you could just send a character from 'a' to 'j'

If you want to send a number of millisecs like (say) 1063 then you will need to have code to receive that and the demos here and here should help. The Arduino code in the second demo also works with the Serial monitor.

...R

Thanks dude!
Do you know how to convert a variable char in a variable int?

ray007:
Thanks dude!
Do you know how to convert a variable char in a variable int?

That's in the demos I linked to.

You can also just read the incoming data as a byte and use it as its Ascii value. For example '0' is 48 and '1' is 49.

...R