UV Light Box – Part 2 – Control Interface

I spent a lot of time working out how I wanted the controls to work and designed the software in C first so that I could work out a generic menu system that allowed me to configure it via an array of menu items.

The definition of the menu items is:

typedef struct {
 int id;
 char *label;
 void (*display_action)();
 void (*select_action)();
 void (*up_action)();
 void (*down_action)();
 int submenu_id;
 int prevmenu_id;
} menu_t;

So each item has an ID and a label followed by a set of actions. When the menu item is first displayed, it’s either the fixed label or, if the label is empty, the display action is called. This allows me to vary the display for things like the timer counter start value where the operator can choose the length of the timer. The select, up and down actions are function calls to vary the behaviour but the left and right actions are always to move to the parent menu or to a submenu.

This structure means that the actual menu handling code is relatively simple. Each button press will call the appropriate function in the structure. It’s the actual functions that can change and I can code for those as I go along.

The code itself is called inside the Arduino loop() function so I’m not using interrupts for the timer and the processor isn’t stuck in delay() cycles. Each time I go around the loop, I am taking the current number of milliseconds since the processor started up and compare that to a previous value I took. If the difference between the current and previous values is over a threshold, I take an action. For a timer, the resolution is seconds so I take the action to update the timer every 1000 milliseconds. For button checking, I take an action every 125 milliseconds.

This video shows the timer and menu system working. I still have some bugs to iron out in terms of timing but it’s working as expected.

Leave a Reply

Your email address will not be published. Required fields are marked *