# include <Wire.h>
# include <LiquidCrystal_I2C.h>
# define BETA 3950.0
# define DELAY_TIME 100
# define STARTING " starting ... "
# define WATERING " watering "
# define NUMBER_BYTE_CODE 0
# define NUMBER_BYTE {B11100, B10100, B11100, B00000, B00000, B00000, B00000, B00000}
# define TEMP_SENSOR_IN A0
# define TIME_LINE 0
# define TEMPERATURE_LINE 1
LiquidCrystal_I2C lcd (0x27, 16, 2);
float current_temp = 0.0;
unsigned short write_lcd = 1;
//const char *ALL_MENU[] = {};
void setup()
{
byte special_char[] = NUMBER_BYTE;
lcd.init();
lcd.createChar(NUMBER_BYTE_CODE, special_char);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.display();
lcd.clear();
lcd.print(STARTING);
Serial.begin(9600);
}
void loop()
{
read_temperature_v2();
display_temperature();
delay(DELAY_TIME);
}
void read_temperature(){
int reading = analogRead(TEMP_SENSOR_IN);
float tmp = ( ( (reading * 5) / 1024.0) - 0.5) * 100;
if (tmp != current_temp){
current_temp = tmp;
write_lcd = 1;
}
}
void read_temperature_v2(){
int reading = analogRead(TEMP_SENSOR_IN);
float tmp = 1 / (log(1 / (1023. / reading - 1)) / BETA + 1.0 / 298.15) - 273.15;
if (tmp != current_temp){
current_temp = tmp;
write_lcd = 1;
}
}
void display_temperature(){
if (!write_lcd) return;
lcd.clear();
char float_str[4];
dtostrf(current_temp, 2, 1,float_str);
lcd.setCursor(5, TEMPERATURE_LINE);
lcd.print(float_str);
lcd.write(NUMBER_BYTE_CODE);
lcd.print("C");
write_lcd = 0;
}