Hardware Reference
In-Depth Information
//Turn off the speaker when it's done
else
{
noTone(SPEAKER);
}
//Turn the Fan on and update display
digitalWrite(FAN, HIGH);
lcd.setCursor(15,1);
lcd.write(2);
}
//If it's not too hot!
else
{
//Make sure the speaker is off
//reset the "one beep" variable
//update the fan state and LCD display
noTone(SPEAKER);
one_time = false;
digitalWrite(FAN, LOW);
lcd.setCursor(15,1);
lcd.write(1);
}
The one_time variable is used to make sure that the beep plays only one time
instead of continuously. Once the speaker has beeped for 500ms at 400Hz, the
variable is set to true and is reset to false only when the temperature drops
back below the desired temperature.
BringingItAllTogether:TheCompleteProgram
It's time to bring all the parts together into a cohesive whole. You need to make
sure that you include the appropriate libraries, define the pins, and initialize
the state variables at the top of the sketch. Listing 10-3 shows the complete pro-
gram. Load it on to your Arduino and compare your results to the demo video
showing the system in action.
Listing 10-3: Personal Thermostat Program—LCD_thermostat.ino
//Keep yourself cool! This is a thermostat.
//This assumes temperatures are always two digits
//Include Wire I2C library and set the address
#include <Wire.h>
#define TEMP_ADDR 72
//Include the LCD library and initialize:
#include <LiquidCrystal.h>
Search WWH ::




Custom Search