#include <OneWire.h>
#include <TimerOne.h>
#include <LiquidCrystal.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 7
#define buttonPin 2
/*
The LiquidCrystal library works with all LCD
displays that are compatible with the Hitachi
HD44780 driver.
This sketch shows the current temperature, and pushing the button
allows it to change from celsius to fahrenheit and vice-versa
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 6
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 4
* LCD D7 pin to digital pin 3
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
DS18B20 temperature sensor pin 7
Pushbutton pin 2
*/
bool tempCelsius = true;
LiquidCrystal lcd_1(12, 11, 6, 5, 4, 3);
// 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
lcd_1.begin(20, 4); // Set up the number of columns and rows on the LCD.
pinMode(buttonPin, INPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), flagSetter, RISING);
}
void loop()
{
// Send the command to get temperatures
sensors.requestTemperatures();
lcd_1.clear();
lcd_1.print("Temperature:");
if (tempCelsius) {
lcd_1.print(sensors.getTempCByIndex(0));
lcd_1.print(char(223));
lcd_1.print("C");
} else {
lcd_1.print((sensors.getTempCByIndex(0) * 9.0) / 5.0 + 32.0);
lcd_1.print(char(223));
lcd_1.print("F");
}
delay(500); // Wait for 100 millisecond(s)
}
void flagSetter(){
tempCelsius = !tempCelsius;
}