Hardware Reference
In-Depth Information
//Turn up the set temp
else if (lastUpTempButton == LOW && currentUpTempButton == HIGH)
{
set_temp++;
}
//Print the set temp
lcd.setCursor(8,1);
lcd.print(set_temp);
//Update the button state with the current
lastDownTempButton = currentDownTempButton;
lastUpTempButton = currentUpTempButton;
The preceding code snippet first runs the debounce() function for each but-
ton, and then adjusts the set temperature variable if one of the buttons has been
pressed. Afterward, the temperature displayed on the LCD is updated, as are
the button state variables.
AddinganAudibleWarningandaFan
In this section, you add code to control the fan and the speaker. Although the
LCD showing you live information is nice, you'll often find it useful to have
an additional form of feedback to tell you when something is happening. For
example, the speaker beeps when the fan turns on. In this example, you use
tone() paired with delay() and a notone() command. You could instead add a
duration argument to tone() to determine the duration of the sound. You want
to make sure that the tone plays only one time so (and does not beep forever
when above the set temperature).
Using a state variable, you can detect when the speaker has beeped and thus
keep it from beeping again until after the temperature dips below the set tem-
perature and resets the state variable.
When the fan turns on, an indicator changes on the LCD (represented by the
custom character you defined at the top of the program). The following code
snippet checks the temperature and controls the speaker, the fan indicator on
the LCD, and the fan:
//If it's too hot!
if (c >= set_temp)
{
//Check if the speaker has already beeped
if (!one_time)
{
tone(SPEAKER, 400);
delay(500);
one_time = true;
}
Search WWH ::




Custom Search