#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int ThermistorPin = 0;
int Vo;
int Svalue = 0;
float R1 = 3950;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
const int DIN_PIN = 2;
void setup()
{
Serial.begin( 9600 );
lcd.init();
lcd.backlight();
lcd.setCursor(4,0);
lcd.print("Temperature: ");
pinMode(2, INPUT_PULLUP);
}
void loop()
{
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Svalue = digitalRead( DIN_PIN );
if (Svalue == 0){
lcd.setCursor(7,1);
lcd.print(celsius);
lcd.print("C ");
Serial.print("Celcius ");
Serial.println( Svalue );
}
else if (Svalue == 1){
lcd.setCursor(7,1);
lcd.print(celsius*9/5+32);
lcd.print("F ");
Serial.print("Farenheit ");
Serial.println( Svalue );
}
else {
lcd.setCursor(0,1);
lcd.print("Switch Error");
Serial.println("Switch Error");
}
}