Go to www.nutsvolts.com/index.php?/magazine/article/october2013_SmileysWorkshop
for any additional files and/or downloads associated with this article. You can also post comments.
if(idle()) // returns 1 if any new key is
if(newKey == CTR)
menu(); // Lets us set temps and
// Show the existing data and wait for a
// void return if a key is pressed
#define IDLEDELAY 500
if(idleState < 6) idleState++;
else idleState = 0;
■ FIGURE 2: Press the center key.
When the idle() function is running, we see the LCD
display. The idle mode shows the text on the LCD for a
period determined by the IDLEDELAY constant used in the
checkKeyDelay function. In Figure 3, we see the flow of
the messages with the delay represented by ‘AUTO’ to
indicate that the LCD text automatically transitions from
one to the next until the user pushes the center button.
This will put the application into the menu mode:
The loop() calls the idle() function that then runs
through all of the functions to display the idle information.
The Idle Mode
This system is going to be sitting around doing
nothing most of the time. Oh, it checks the sensors every
so often and turns the attic fan on and off occasionally,
but mostly it just twiddles its digital thumbs. We can use
some of that excess processing power by displaying a
rotating series of LCD messages to show the user what the
various indoor and outdoor temperature and humidities
are, along with the various set points.
It prints the data name on the first line; the data value on
the second line; then it calls checkKeyDelay(IDLEDELAY) —
the function that checks the key while also delaying for
the indicated time, allowing the LCD to display the data
for the indicated time. If no key is pressed, then the next
set of data is displayed and the buttons checked, and so
on until either a key is detected or the data is all
displayed. If no key is detected, then the function returns
0 to the loop which runs the idle() function again.
The idle() function does some stuff that — among
other things — includes checking to see if a key is pressed.
If a key is detected, the idle() function returns 1 and
the loop checks to see if there really is a new key
available. If the button was CTR, the program runs the
menu() function that lets the user input the temperature
and humidity settings.
If the button is pressed, it returns 1; otherwise, it returns 0.
The ‘some stuff’ mainly consists of showing the user some
data on the LCD and checking the control algorithm to
see if the fan should be on or off:
The Menu Mode
One really great thing about the Arduino handheld
62 October 2013