Best control structure for task of aligning motor with sensor

Just about got it. I just have to finish the compass routine, and add a motor time-out, and I'll be ready to test it on the real deal. Currently, I have a breadboard set up with the diagnostic and status LEDs, and input switches to test as I go.

Many thanks to Allan, Dave, and Robin for your help and advice. I have a clean (to me) sketch, with well defined functions. The loop part only has about 46 lines, some of which are comments, everything else is handled by ISRs and defined functions. The sketch in total has 487 lines so far, and the only part not hand written is the routine to convert the compass' raw data to a heading. (I don't remember trigonometric functions as well as I ought..)

It's been a real learning experience, for sure. Robin's "rules of order" really help to keep things organized. I'd post the results of my labors, but I'm afraid someone who actually knows what they are doing would be offended that I used 500 lines when they could have done the same thing with 20 lines, LOL. I still haven't worked with strings and arrays, and the compass library had some signs and commands I didn't recognize, either.

Arduinos being relatively simple things, I cannot imagine how folks write programs for modern, multi-core and multi-threaded systems. How do they keep all this stuff straight in their heads?