#include <LiquidCrystal.h> // Contains LiquidCrystal library
#include <FlexiTimer2.h> // Contains FlexiTimer2 Library
// initialize the libary with the numbers of the interface pins
LiquidCrystal lcd(11, 5, 4, 3, 2);
int tempPin = 4; // pin for temperature sensor
float tempVal; // store temperature value
int hour, minute, second; // records time
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2); // set up LCD's umber of columns and rows
startingAnimation(); // dynamic start screen
FlexiTimer2::set(1000, timerInt); // configure timer and interrupt function
FlexiTimer2::start(); // start timer
Serial.begin(115200); // baud rate 115220 symbols per second
Serial.println("Input hour,minute,second to set time");
}
void loop() {
// put your main code here, to run repeatedly:
// get temperature
tempVal = getTemp();
if(second >= 60){ // 60 seconds --> 1 minute
second = 0;
minute++;
if(minute >= 60){ // 60 minutes --> 1 hour
minute = 0;
hour++;
if(hour >= 24){ // 24 hours --> 0 hours
hour = 0;
}
}
}
lcdDisplay(); // display temperature and time on LCD
delay(200);
}
void startingAnimation(){
for(int i = 0; i < 16; i++){
lcd.scrollDisplayRight();
}
lcd.print("starting...");
for(int i = 0; i < 16; i++){
lcd.scrollDisplayLeft();
delay(300);
}
lcd.clear();
}
void timerInt(){
second++;
}
void serialEvent(){
int inInt[3];
while(Serial.available()){
for(int i = 0; i < 3; i++){
inInt[i] = parseInt();
}
Serial.print("Your input is: ");
Serial.print(inInt[0]);
Serial.print(", ");
Serial.print(inInt[1]);
Serial.print(", ");
Serial.print(inInt[2]);
Serial.print("Time now is: ");
Serial.print(hour / 10);
Serial.print(hour % 10);
Serial.print(' :');
Serial.print(minute/10);
Serial.print(minute % 10);
Serial.print(' :');
Serial.print(second/10);
Serial.println(second%10);
}
}
void lcdDisplay(){
lcd.setCursor(0,0);
lcd.print("TEMP: ");
lcd.print(tempVal);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("TIME: ");
lcd.print(hour/10);
lcd.print(hour % 10);
lcd.print(' :');
lcd.print(minute/10);
lcd.print(minute%10);
lcd.print(' :');
lcd.print(second/10);
lcd.print(second%10);
}
float getTemp(){
int adcVal = analogRead(A4);
float v = adc * 5.0/1024;
float Rt = 10 * v / (5 - v);
float tempK = 1 / (log(Rt / 10) / 3950 + 1 / (273.15 + 25));
return tempK - 273.15;
}