Okay, there's a few things to think about. You definitly need a variable for the absolute position.
To keep things simple, I would say that the stepper finnishes it's motion every time a sensor detects something. In other words, if sensor1 detected something and starts movement to 30 degrees, interrupts from the other sensors are ignored untill the stepper is at 30 degrees.
There is some info at the InterruptIn "Working with Interrupts" in the handbook on how to dissable interrupts temporarily I believe. (I think you'll want your sensor connections to be of the kind interruptIn)
You basically have three target positions. And you have to calculate howmany steps have to be moved from the absolute position.
If your sensor3 detects something and the stepper motor is at absolute position 0, the stepper has to move for 83 steps (1333 at 16th microstep). You basicly do target-absolute every time.
So now your motor moved to the absolute position of 1333. And sensor 1 fires.
The target position is now 17 steps (267 at 16th). 267-1333 = -1067. Result<0? change direction and do 1333-267 instead.
This should be relatively easy to implement on top of my example code or on your own code.
Hope it helps.
Melchior
Hi, I'm kinda new in electronics and aslo in C programming .any advise on how to control the position of a stepper using pololu stepper driver. I want to move the stepper to three position. position 1 - 45 degree, position 2- 90 degree and position 3- 135 degree and my stepper has a 7.5 degree step angle .
please give me some advise.
Thank you.