Controlling lots of stuff

Some references

The super loop

Traditional

void main(void) {
  Initialize1();
  Initialize2();
  ...
  Initializen();
  while(1) {
    Work1() ;
    Work2() ;
    ...
    Workn();
  }
}

Arduino

void setup() {
  Initialize1();
  Initialize2();
  ...
  Initializen();
}

void loop() {
  Work1() ;
  Work2() ;
  ...
  Workm();
}

Problems

How about music or PWM

Interrupts and Timers

Arduino examples

But be very careful. This is complicated stuff.

Alternatives

Think about using a linked list of things to be done. These are common in read operating systems.

Operating systems

Services of the operating system

The world of RTOS