Suppose I have something like an analogue clock with just a single hand driven by a 12-position stepper motor. Let's also suppose that at any instance I know where the hand is.
What I want is an algorithm that I call with the current position (0-11), the new position (0-11) and a flag. What I want it to return is the number of steps to move and the direction (indicated by the sign, +ve = CW, -ve = CCW) based on taking either the shortest or longest route (determined by the flag parameter) from the current to the new position.
int8_t steps_to_take(uint8_t old, uint8_t new, uint8_t shortest)
I have some code to do this but it relies on multiple if-then-else statements nested 3 deep to determine all the various outcomes.
It feels like there ought to be a really elegant solution to this but after many hours I'm not seeing it.
Anyone up for the challenge?