Looking at Arduino examples, many seem content with making a stepper go 20 ticks and have the program blocked until done.
How does it look in real life if you have say a serial listener receiving commands and controlling 10 steppers? Would you have an event loop with say sleep(100us) and iterating a data structure or do you do something more intricate like Protothreads or some other featherweight "os"?
How do you generate the stepper signals, by software toggling pins high/low? If so what is the timing accuracy that you need to make these bit flips?
An arduino program looks like this
void setup() {
}
void loop() {
}
If you want to have multi tasking you can do it by emulating multiple arduino programs
void setup1() {
}
void loop1() {
}
void setup2() {
}
void loop2() {
}
...
and then implement the main as
void setup() {
setup1();
setup2();
...
}
void loop() {
loop1();
loop2();
...
}
Just make sure not to use delay() and similar busy loops in the loop() functions and make your timing decisions based on state variables and milliseconds(). For example, a led blinking task can look like this pseudo code
static long ms_at_last_chagne;
static boolean last_value;
void setup_led_blinking() {
set LED pin mode to output
set LED pin high
ms_at_last_chagne = millseconds();
boolean last_value = true;
}
void loop_led_blinking {
// Need to do anything?
if ((millisecods() - ms_at_last_chagne) < 500) {
return;
}
// Flip pin.
last_value = !last_value;
set LED pin to last_value;
// You can use the current time or keep tracking the old schedule.
ms_at_last_chagne += 500;
}