#include <LiquidCrystal.h>
#include <math.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup(void)
{
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
}
float Getterm(int RawADC)
{
float celsius = 1 / (log(1 / (1023. / RawADC - 1)) / 3950 + 1.0 / 298.15) - 273.15;
return celsius;
}
float Filter(float x, int j)
{
static float arr[3][10] = {0};
float temp = 0;
arr[j][0] = x;
for(const auto& el : arr[j])
{
temp += el;
}
for(int i = 9; i > 0; i--)
{
arr[j][i] = arr[j][i-1];
}
return (temp/10);
}
float Average(float& temp1, float& temp2, float& temp3)
{
return (temp1 + temp2 + temp3) / 3;
}
void loop(void)
{
float temp1 = Filter(Getterm(analogRead(A0)), 0);
float temp2 = Filter(Getterm(analogRead(A1)), 1);
float temp3 = Filter(Getterm(analogRead(A2)), 2);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("Max");
lcd.setCursor(6, 0);
lcd.print("Min");
lcd.setCursor(12, 0);
lcd.print("Avg");
lcd.setCursor(0,1);
lcd.print(max(max(temp1, temp2), temp3), 1);
lcd.setCursor(5, 1);
lcd.print(min(min(temp1, temp2), temp3), 1);
lcd.setCursor(11, 1);
lcd.print(Average(temp1, temp2, temp3), 1);
delay(100);
}