my friend gave me this code, but it needs some modifications to make it so that i only need it to count the current temp. and the avarage as said in original post:
#include <LiquidCrystal.h>
#include <math.h>
const char *button[5] ={"Right ", "Up ", "Down ", "Left ", "Unknown "};
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned long prevTime = 0;
unsigned long debounceDelay = 200;
unsigned long lastDebounceTime = 0;
int limh = 0;
int liml = 0;
double temp = 0;
//Buttons
#define btnRight 0
#define btnUp 1
#define btnDown 2
#define btnLeft 3
#define btnUnknown 4
//Button readings
int buttons(){
int buttonread = analogRead(0);
int ret = btnUnknown;
if(buttonread < 10) ret = btnRight;
if((buttonread > 140) && (buttonread < 150)) ret = btnUp;
if((buttonread > 320) && (buttonread < 340)) ret = btnDown;
if((buttonread > 500) && (buttonread < 520)) ret = btnLeft;
return ret;
}
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("Thermistor");
delay(1000);
lcd.clear();
}
void loop() {
int analogvalue = analogRead(A1);
//Steinhart-Hart equation
if((millis() - prevTime) >=2000) {
temp = log(10000.0/((1024.0/analogvalue-1)));
temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * temp * temp ))* temp );
temp = temp - 273.15; // Kelvin to celcius
prevTime = millis();
//Round temp
//int roundTemp = round(temp);
}
if((millis() - lastDebounceTime) > debounceDelay) {
//LIMH
if(buttons() == btnUp) {
lcd.clear();
limh++;
}
if(buttons() == btnDown) {
lcd.clear();
limh--;
}
//LIML
if(buttons() == btnLeft) {
lcd.clear();
liml++;
}
if(buttons() == btnRight) {
lcd.clear();
liml--;
}
lastDebounceTime = millis();
}
if(temp < limh && temp > liml) {
lcd.setCursor(12,1);
lcd.print("NORM");
}
if(temp > limh) {
lcd.setCursor(12,1);
lcd.print("HIGH");
}
if(temp < liml) {
lcd.setCursor(12,1);
lcd.print("LOW");
}
lcd.setCursor(0, 1);
lcd.print("TMP:");
lcd.setCursor(4, 1);
lcd.print(temp);
//Display on LCD
lcd.setCursor(0,0);
lcd.print("LIMH:");
lcd.setCursor(5,0);
lcd.print(limh);
lcd.setCursor(8,0);
lcd.print("LIML:");
lcd.setCursor(13,0);
lcd.print(liml);