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
- Might be a lot of things in the loop
- Time through the loop may be hard to figure
- Some activities are more important than others
- Some activities are much more frequent than others
- Activities may depend on the state
- Some activities have delays
- May use power
- May not be very modular
How about music or PWM
- In a subloop?
- Calling
analogWrite()
-- if available
- Checking the time in the super loop
- Call
delay
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
- Create tasks/threads/tasklets
- Synchronize threads
- Manage memory
- Support "files" (on SD cards are in flash)
- See
pthread
API
The world of RTOS
- Arduino
- Big embedded systems