I am trying to run a stepper motor with its compatible driver. Simply sending a series of pulses, moves the motor.
A pulse train output causes continuous rotation and single pulse causes the stepper to move one step (Jogging).
With the attached code I am able to make continuous rotation but not jogging.
Speed setting is done by analog input on pin A0.
What changes are required to make to able to jog also?
In that program the mode and the speed are only read once in setup(). And you may not be quick enough to press the button when the program starts.
It would be more usual to read the buttons and the potentiometer regularly in loop(). And that is essential if you want to jog more than one single step. Have a look at Planning and Implementing a Program
You should also note how my demo code uses millis() to manage timing without blocking. The Arduino can do nothing during a delay() which makes for an unresponsive program.
arihant122:
I have made changes as suggested but it still won't work.
You need to tell us what is actually does. "Won't work" is not helpful for debugging.
Why do you need a DO/WHILE for a single step? Just use IF.
Using floating point for the speed variable is a waste of time. The delay() function takes an integer as its paramter. Only use floating point maths on a microprocessor if it is unavoidable - it is very slow.
Put in some Serial.print() statements so you can see what the code is doing - what is the value of mode, or speed, and what part of the program is being activated.
For anything beyond a trivial program it is better to give names to pins to make the code clearer. For example