//Hi, i'm new to all this, the code here does output stepper pulses while I keep pin2 pressed , but I wish it to run to completion after just a short press.
Any further pin2 presses must be ignored until stepperun has finished.
This simple code doesn't allow a repeat event if pin2 is pressed again later either.
but I wish it to run to completion after just a short press.
You need to look at the state change detection example. Learn to determine when a switch BECOMES pressed, not IS pressed.
This simple code doesn't allow a repeat event if pin2 is pressed again later either.
Where do you define where the stepper is to go to? In setup(). Unless you define a new position, once it steps 400 times, it's done.
I don't really see a reason for you to be using AccelStepper, Stepper would do what you want, in a much easier to understand fashion. The drawback is that it is blocking, but that seems to be what you want, so it isn't really a drawback.