#include <LiquidCrystal_I2C.h>
#define I2C_ADDR    0x27
#define LCD_COLUMNS 20
#define LCD_LINES   4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int targetTemp = 60;
//int currentTemp = 0;
const int threshold = 5;
const int upRelayPin = 13;
const int dwnRelayPin = 12;
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void setup() {
  // Init
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
}
void loop() {
//ntc analog temp code
  int analogValue = analogRead(A0);
  float currentTemp = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
  // Serial.print("Temperature: ");
  //Serial.print(currentTemp);
  //Serial.println(" ℃");
//float currentTemp = (tempCelsius * 1.8) + 32;
//**ntc
  // Print something
  lcd.setCursor(1, 1);
  lcd.print("Current Temp: ");
  lcd.print(currentTemp);
  lcd.setCursor(1, 3);
  lcd.print("Target Temp: ");
  lcd.print(targetTemp);
  //lcd.clear();
  
  //tempup
  if (currentTemp > targetTemp + threshold) {
    digitalWrite(upRelayPin, HIGH);
  } else {
    digitalWrite(upRelayPin, LOW);
  }
  //tempdown
   if (currentTemp < targetTemp - threshold) {
    digitalWrite(dwnRelayPin, HIGH);
  } else {
    digitalWrite(dwnRelayPin, LOW);
  }
delay(500);
}