#include <Wire.h>
#include <OneWire.h>
#include <TimerOne.h>
#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 7
#define buttonPin 2
/*
This sketch shows the current temperature, and pushing the button
allows it to change from celsius to fahrenheit and vice-versa
DS18B20 temperature sensor pin 7
Pushbutton pin 2
*/
bool tempCelsius = true;
//initialize the liquid crystal library
//the first parameter is the I2C address
//the second parameter is how many rows are on your screen
//the third parameter is how many columns are on your screen
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
void setup()
{
sensors.begin(); // Start up the library
//initialize lcd screen
lcd.init();
// turn on the backlight
lcd.backlight();
lcd.setCursor(0,0);
pinMode(buttonPin, INPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), flagSetter, RISING);
}
void loop()
{
// Send the command to get temperatures
sensors.requestTemperatures();
lcd.clear();
lcd.print("Temperature:");
if (tempCelsius) {
lcd.print(sensors.getTempCByIndex(0));
lcd.print(char(223));
lcd.print("C");
} else {
lcd.print((sensors.getTempCByIndex(0) * 9.0) / 5.0 + 32.0);
lcd.print(char(223));
lcd.print("F");
}
delay(1000);
}
void flagSetter(){
tempCelsius = !tempCelsius;
}