#include <LiquidCrystal_I2C.h>
#define temp A0
const float BETA = 3950;
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
byte pos = 0;
boolean dir = true;
void setup ()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(temp, OUTPUT);
lcd.init();
lcd.backlight();
}
void loop ()
{
// put your main code here, to run repeatedly:
float currTemp = analogRead(temp);
float convertedTemp = 1 / (log(1 / (1023. / currTemp - 1)) / BETA + 1.0 / 298.15) - 273.15;
if ( dir )
{
if ( pos < 15 )
{
pos ++;
lcd.scrollDisplayRight ();
}
else dir = false;
}
else
{
if ( pos > 0 )
{
pos --;
lcd.scrollDisplayLeft ();
}
else dir = true;
}
lcd.setCursor(0, 0);
lcd.print(convertedTemp);
delay(200);
}