Hardware Reference
In-Depth Information
You also update the fan indicator and temperature values each time through
loop() . You need to move the cursor to the right location each time before you
update these characters.
AdjustingtheSetPointwithaButton
In Chapter 2, you used a debounce() function. Here, you modify it slightly to
use it with multiple buttons. One button will increase the set point, and the
other will decrease it. You need to define variables for holding the previous
and current button states:
//Variables for debouncing
boolean lastDownTempButton = LOW;
boolean currentDownTempButton = LOW;
boolean lastUpTempButton = LOW;
boolean currentUpTempButton = LOW;
You can modify the debounce() function to support multiple buttons. To
accomplish this, add a second argument that specifies which button you want
to debounce:
//A debouncing function that can be used by both buttons
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}
In loop() , you want to check both buttons using the debounce() function,
change the set_temp variable as needed, and update the set value that is dis-
played on the LCD:
//Debounce both buttons
currentDownTempButton = debounce(lastDownTempButton, DOWN_BUTTON);
currentUpTempButton = debounce(lastUpTempButton, UP_BUTTON);
//Turn down the set temp
if (lastDownTempButton == LOW && currentDownTempButton == HIGH)
{
set_temp--;
}
Search WWH ::




Custom Search