//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
// Declaration of global variables
int analogPin_0 = A0;
int analogVal_0 = 0; // Variable to store the value read
int Temperatur_0 = 0; // Actual temperature
int Temp_max_0 = 0; // Maximum temperature
int analogPin_1 = A1;
int analogVal_1 = 0; // variable to store the value read
int Temperatur_1 = 0; // Actual temperature
int Temp_max_1 = 0; // Maximum temperature
int analogPin_2 = A2;
int analogVal_2 = 0; // variable to store the value read
int Temperatur_2 = 0; // Actual temperature
int Temp_max_2 = 0; // Maximum temperature
int analogPin_3 = A3;
int analogVal_3 = 0; // variable to store the value read
int Temperatur_3 = 0; // Actual temperature
int Temp_max_3 = 0; // Maximum temperature
const float vt_factor = 2.0; // Correction factor
const float offset = 0; // Offset
bool Reset = false;
unsigned long TimeAct, TimePrev;
unsigned short Timer_1;
bool Pulse_1s;
unsigned long Task_Timer_1;
#define Reset_BUTTON 13
// ------------------------------------------------------
// SETUP
// ------------------------------------------------------
void setup()
{
pinMode(Reset_BUTTON, INPUT_PULLUP);
Serial.begin(9600);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(5,0);
lcd.print("POWERED BY");
lcd.setCursor(7,1);
lcd.print("AMU LTD");
}
// ------------------------------------------------------
// TASKS
// ------------------------------------------------------
void Pulse() // Generates a pulse every second
{TimeAct = millis(); // Millis value between 0 and 655535
Pulse_1s = false;
if ( ( (TimeAct > TimePrev) and (TimeAct - TimePrev) > 1000) or ((TimeAct < TimePrev) and (65535 - TimePrev + TimeAct) > 1000 ) ) {
Pulse_1s = true;
TimePrev = TimeAct;
}
}
void Task_Schedule() // Runs tasks at scheduled time
{
if (Pulse_1s == true)
{
Task_Timer_1++;
}
if (Task_Timer_1 == 5) // Runs tasks every 5 seconds
{
Analog_Read();
Display();
Task_Timer_1 = 0;
}
}
void Analog_Read()
{
// Conversion of analog input A0
analogVal_0 = analogRead(analogPin_0); // read the input pin
float voltage_0 = analogVal_0 * (5.0 / 1023.0);
float temp_0 = (((voltage_0 * 100) / vt_factor) + offset);
Serial.println(analogVal_0);
Temperatur_0 = temp_0;
if (Temperatur_0 > Temp_max_0)
{
Temp_max_0 = Temperatur_0;
}
// Conversion of analog input A1
analogVal_1 = analogRead(analogPin_1); // read the input pin
float voltage_1 = analogVal_1 * (5.0 / 1023.0);
float temp_1 = (((voltage_1 * 100) / vt_factor) + offset);
Serial.println(analogVal_1);
Temperatur_1 = temp_1;
if (Temperatur_1 > Temp_max_1)
{
Temp_max_1 = Temperatur_1;
}
// Conversion of analog input A2
analogVal_2 = analogRead(analogPin_2); // read the input pin
float voltage_2 = analogVal_2 * (5.0 / 1023.0);
float temp_2 = (((voltage_2 * 100) / vt_factor) + offset);
Serial.println(analogVal_2);
Temperatur_2 = temp_2;
if (Temperatur_2 > Temp_max_2)
{
Temp_max_2 = Temperatur_2;
}
// Conversion of analog input A3
analogVal_3 = analogRead(analogPin_3); // read the input pin
float voltage_3 = analogVal_3 * (5.0 / 1023.0);
float temp_3 = (((voltage_3 * 100) / vt_factor) + offset);
Serial.println(analogVal_3);
Temperatur_3 = temp_3;
if (Temperatur_3 > Temp_max_3)
{
Temp_max_3 = Temperatur_3;
}
}
void Display() // Controlls display readings
{
lcd.clear();
// First line
lcd.setCursor(0,0);
lcd.print("L1");
lcd.setCursor(3,0);
lcd.print("Act:");
lcd.setCursor(7,0);
lcd.print(Temperatur_0);
lcd.setCursor(11,0);
lcd.print("Max:");
lcd.setCursor(15,0);
lcd.print(Temp_max_0);
lcd.setCursor(18,0);
lcd.write(0xDF);
lcd.setCursor(19,0);
lcd.print("C");
// Second line
lcd.setCursor(0,1);
lcd.print("L2");
lcd.setCursor(3,1);
lcd.print("Act:");
lcd.setCursor(7,1);
lcd.print(Temperatur_1);
lcd.setCursor(11,1);
lcd.print("Max:");
lcd.setCursor(15,1);
lcd.print(Temp_max_1);
lcd.setCursor(18,1);
lcd.write(0xDF);
lcd.setCursor(19,1);
lcd.print("C");
//Third line
lcd.setCursor(0,2);
lcd.print("L3");
lcd.setCursor(3,2);
lcd.print("Act:");
lcd.setCursor(7,2);
lcd.print(Temperatur_2);
lcd.setCursor(11,2);
lcd.print("Max:");
lcd.setCursor(15,2);
lcd.print(Temp_max_2);
lcd.setCursor(18,2);
lcd.write(0xDF);
lcd.setCursor(19,2);
lcd.print("C");
// Fourth line
lcd.setCursor(0,3);
lcd.print("L4");
lcd.setCursor(3,3);
lcd.print("Act:");
lcd.setCursor(7,3);
lcd.print(Temperatur_3);
lcd.setCursor(11,3);
lcd.print("Max:");
lcd.setCursor(15,3);
lcd.print(Temp_max_3);
lcd.setCursor(18,3);
lcd.write(0xDF);
lcd.setCursor(19,3);
lcd.print("C");
}
// ------------------------------------------------------
// MAIN LOOP
// ------------------------------------------------------
void loop()
{
Pulse(); // Generate pulse for 1s
Task_Schedule(); // Task Schedule
// Reset Max Values
if (digitalRead(Reset_BUTTON) == LOW) {
Reset = HIGH;
}
if (digitalRead(Reset_BUTTON) == HIGH && Reset == true) {
Temp_max_0 = 0;
Temp_max_1 = 0;
Temp_max_2 = 0;
Temp_max_3 = 0;
Reset = false;
}
}