Photo-Tom:
- While the stepper is actively rotating there should be a delay in making it rotate again for a certain amount of time, (say 5 seconds).
That all seems clear, apart from the piece I have quoted. Do you mean that when it moves 200 steps CW it should wait 5 seconds before the 200 CCW steps?
OR, do you mean that after it has done one out-and-back it should not start another one for at least 5 seconds?
Assuming the latter, I think I would write the program like this pseudo code ...
if PIR is detected
PIRdetected = true
motorDirection = 'F'
motorMoving = false
if PIRdetected == true
if motorMovng == false
if motorDirection == 'F'
moveTo 200
motorMoving = true
else // meaning motorDirection == 'R'
moveTo -200
motorMoving = true
if motorMoving == true and distanceToGo == 0
motorMoving = false
if motorDirection = 'F'
motorDirection = 'R'
else
PIRdetected = false
motorDirection = 'F'
stepper.run()
I have not built the 5 second interval into the above.
I have used 'F' to mean CW and 'R' to mean CCW
...R