Programming stepper motors to move until limit switches

The "homing" approach that most people take, which is very reliable, can be outlined like this.
The code assumes that an open switch is read as HIGH.

while (digitalRead(switchpin) == HIGH) take_one_step();

Of course, nothing can happen during delay(), and for responsive programming, you should learn how to remove most, if not all of those calls to delay().

2 Likes