First sketch for the main controller

Here is a event-driven version for the main controller. Hope it will
work well.