Hi
Iron Man, thank you for trying to help, I looked link that you provide and I think that I do not see there what I need. I made perfectly working macro for tool changer only thing is that I need to postion/rotate turret manually before I can use it, and it is based on assumption that turret is made symmetrical (which is true). I added optical sensor that need to stop turret when it is being activated (I can set when it needs to be activated by rotating plastic ring with small hole).
Basically I need code that will stop movement of stepper motor when my sensor is activated , it sounds very simple but I can not find part of code on internet where I see that that is going on so I can use it, this is what I am looking for.

So I give order to stepper motor to rotates by pressing button REF and I want to rotation be continues and I want to motor stops same millisecond when sensor is triggered.

I manage to use loop for my idea (do while) but it only works like this:

rotate rotor of motor for certain angle and check is sensor triggered, if it is not triggered then rotate it again, to be able to find random hole on my plastic disc rotation of rotor need to be for small angle and that means motor needs to cross through loop lot of time and that makes process very slow, and I do not like that but I do not know how to make it faster (continues rotation that will be stopped when sensor is triggered).

I hope I described detail enough what I am trying to do.

Thx in advance to everybody who will try to help.

Marko