//--------LIBRERIE-------------------------
#include <LiquidCrystal_I2C.h> //lcd
#include <Keypad.h>
#include <EEPROM.h>
//-----------------------------------------
//----------------LCD----------------------
LiquidCrystal_I2C lcd(0x27,20,4);
//-----------------------------------------
//-----Tastierino------------
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
//------------------------MENU-------------------------
//-------------------------------------------------------
//------------TMP-------------
const float BETA = 3950;
int val = 0;
int sensore = A0;
int temp = 0;
//-----------------------------
int stato = 0;
bool x = 0;
bool o = 0;
bool i = 0;
bool time = 0;
//--------------------------
//--------------------------
void setup()
{
//----------EEPROM------------
int v_val = EEPROM.read(0);
//----------------------------
//----------LCD---------------
lcd.init();
//----------------------------
//----------TMPSENS-----------
pinMode(sensore, INPUT);
Serial.begin(9600);
//----------------------------
}
//--------------------------
//--------------------------
int key = 0;
void loop()
{
leggo_temp();
switch(stato){
case 0:
showSpalshScreen();
lcd.clear();
if(x == 1) stato = 1;
break;
case 1:
LCD();
menu();
lcd.setCursor(0,1);
char key = keypad.getKey();
lcd.print(key);
Serial.print(stato);
break;
case 2:
Serial.print("Aaaa");
lcd.clear();
stato = 3;
break;
case 3:
Serial.print(stato);
writing();
break;
}
}
void leggo_temp(){
val = analogRead(sensore);
temp = 1 / (log(1 / (1023. / val - 1)) / BETA + 1.0 / 298.15) - 273.15;
if(temp >= -9 ){
lcd.setCursor(14,0);
lcd.print(" ");
}
/*
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" ℃");
*/
}
void LCD(){
lcd.setCursor(0, 0);
lcd.print("Temperature:");
lcd.setCursor(12, 0);
lcd.print(temp);
lcd.setCursor(15, 0);
lcd.print("C");
}
void menu(){
bool conf = 0;
char key = keypad.getKey();
if(key == 'A') stato = 2;
if(key == 'D') conf = 0;
if(key == 'C') conf = 1;
}
void showSpalshScreen() {
lcd.setCursor(0,0);
lcd.print("Carotti Spa.");
lcd.setCursor(3, 1);
String message = "Loading...";
for (byte i = 0; i < message.length(); i++) {
lcd.print(message[i]);
delay(50);
}
delay(500);
x = 1;
}
void writing (){
lcd.setCursor(0,0);
lcd.print("Impostare Temp:");
char key = keypad.getKey();
lcd.setCursor(0,1);
lcd.print(key);
if(key > 80){
lcd.setCursor(0,1);
lcd.print("ERROR");
delay(1000);
lcd.print("MAX Value 80");
//lcd.clear();
}
}
/* valore che deve ricordare EEPROM
int valore = 100;
EEPROM.write(0, valore);
*/