/*Overall, the code orchestrates a control cycle for a refrigeration system,
incorporating temperature monitoring, cooling, defrosting, and various indicators for system status.
The LCD provides real-time information, and the code includes mechanisms to handle potential issues like 
cooling failures.
Further analytic explanation can be found in the doc file within the same folder*/



//==========================================================================
//==========================================================================
//===========================================================================

/*Before real operation adjust the following;

1- pins
2- const unsigned long defrostInterval = 600000;  // Defrost interval in milliseconds (60 seconds)
3- const int defrostDuration = 3000; // defrost duration
4- const int secondsThreshold = 10; // threshold time elapseed for monitoring temperature
5- const int monitorTempThreshold = -10;  // Added threshold for monitoring temperature
6- const unsigned long blinkInterval = 500;// Define the blinking interval for pin 41 in milliseconds
7- const unsigned long resetInterval = 20*24*60*60*1000; // Define the interval for global automatic reset in milliseconds (2 minutes)
8- if (freezerTemperatureAboveThreshold(5, 10000)); // time & seconds
9- scrollMessage(1, scrollingMessage, 600, totalColumns); // Scroll speed the predefined message on the LCD
10-delays()
11-units of time
12-for (int countdown = 300; countdown > 0; countdown--) // startup count down
*/


#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <TimerOne.h>



const int pin_RS = 8;
const int pin_EN = 9;
const int pin_d4 = 4;
const int pin_d5 = 5;
const int pin_d6 = 6;
const int pin_d7 = 7;
const int pin_BL = 10;
LiquidCrystal lcd(pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7);

// Define LCD display parameters
int totalColumns = 16;
int totalRows = 2;

unsigned long startTime;
unsigned long elapsedTime;

void setup() {
  lcd.begin(16, 2);  // Adjust the LCD size based on your display
  lcd.clear();
  
  startTime = millis();  // Record the start time
}

void loop() {
  // Update elapsed time
  elapsedTime = millis() - startTime;

  // Display elapsed time in seconds
  lcd.setCursor(0, 0);
  lcd.print("Time: ");
  lcd.print(elapsedTime / 1000);
  lcd.print("s");

  // Display scrolling text
  lcd.setCursor(0, 1);
  scrollText("Hello, World! ");

  delay(500);  // Adjust the delay based on your preference for scrolling speed
}

void scrollText(const char* text) {
  static int textPosition = 0;

  lcd.print("                ");  // Clear the line

  lcd.setCursor(textPosition, 1);
  lcd.print(text);

  textPosition++;
  if (textPosition > totalColumns - 1) {
  textPosition = 0;
}
}
freezer
fridge
room
cooling
(-10°C~0°C)
defrosting
(3sec/1min )
alarm
(>5°C)
(-55°C to +125°C)