Moved Arduino sketch to toplevel.
Improved idle detection logic.