#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DallasTemperature.h>
LiquidCrystal_I2C lcd_1 = LiquidCrystal_I2C(0x27, 16, 2);
//Variable Declarations:
int FreezerTemp = 0;
int FridgeTemp = 0;
int FreezerMaxTemp = -40; //Used for temperature in F
int FridgeMaxTemp = -40; //Used for temperature in F
int DisplayMaxTempsButton = 0;
int ResetMaxTempsButton = 0;
int numberOfTempProbes;
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
void setup() {
// put your setup code here, to run once:
Wire.begin();
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
numberOfTempProbes = sensors.getDeviceCount();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(numberOfTempProbes, DEC);
Serial.println(" devices.");
// Loop through each device, print out address
for(int i=0;i<numberOfTempProbes; i++) {
// Search the wire for address
if(sensors.getAddress(tempDeviceAddress, i)) {
Serial.print("Found device ");
Serial.print(i, DEC);
Serial.print(" with address: ");
//Serial.print(tempDeviceAddress);
Serial.println();
} else {
Serial.print("Found ghost device at ");
Serial.print(i, DEC);
Serial.print(" but could not detect address. Check power and cabling");
}
}
//initiate the LCD
lcd_1.init();
lcd_1.backlight();
}
void loop() {
//lcd_1.clear();
//lcd_1.setCursor(2,0);
//lcd_1.print("Hello World");
//lcd_1.setCursor(5,1);
//lcd_1.print("Second row");
FridgeTemp = sensors.getTempFByIndex(0);
FreezerTemp = -40 + 0.878679 * (analogRead(A1)-20);
lcd_1.setCursor(0,0);
lcd_1.print("Fridge: ");
//lcd_1.setCursor(8,0);
lcd_1.print(FridgeTemp);
lcd_1.setCursor(0,1);
lcd_1.print("Freezer: ");
delay(1000);
}