Hi @vasanthk230,
welcome to the arduino-Forum.
Do you use the two stepper-motors for exact positioning something or for something else?
You should post an overview about what your project is.
Depending on your overall project different solutions fit best.
It is very likely that using the MobaTools-library will make driving the two stepper-motors much easier.
The MobaTools-library creates the step-pulses based on a timer-interrupt in the background.
You do a simple single call of a function and the library is creating all the step-pulses.
infinitely or a specified amount of steps
whenever you want to stop the motors make a single call to function .stop()
If you want to move two stepper-motors based on elementary function-calls like
digitalWrite()
Your can't use two for-loops. You have to use a single loop and the best thing is to use void loop() as the loop that is looping because
void loop() IS looping anway all the time
You have two functions. One for motor1 one for motor2
These two functions were repeatedly called by
void loop()
with each call of these two functions the following things must be done:
1.) checking if enough time has passed by to create the next step
2.) if the time has come to do a step going one further in the switching sequence switching the outputs LOW/HIGH
this means void loop() must run very fast to be able to check multiple times faster if it is time to create a new step and if the time has come to do so.
All these details are managed by the mobatools-library and you don't have to care about these details
The mobaTools-library can be installed with the library-manager of the arduino-IDE
If you post precise information how the gradually changing speed shall happen I can write a small demo-code that shows how this can be coded with the mobatools-library
example-description for gradually changing speed:
starting at 60 rpm and once every 10 seconds increase speed by 1 rpm
0:00 60 rpm
0:01 60 rpm
0:02 60 rpm
...
0:09 60 rpm
0:10 61 rpm
0:11 61 rpm
0:12 61 rpm
...
0:19 61 rpm
0:20 62 rpm
etc.
or you draw a timing-diagram that shows it
best regards Stefan