#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <DHT.h>
#include "OneButton.h"
#include <SPI.h>
#include <SD.h>
// for arduino mega
#define HEATER_PIN 6
#define BAC_HEATER_PIN 6
#define HFIRE_PIN 7
#define MOTOR_F_PIN 12
#define MOTOR_B_PIN 12
#define FAN_PIN 9
#define ALARM_PIN 0
const int btn1 = 2;
const int btn2 = 3;
const int btn3 = 4;
const int btn4 = 5;
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_MOSI 51
#define TFT_CLK 52
// SD Card Module
#define SD_CS 13
#define SD_MOSI 51
#define SD_MISO D6
#define SD_CLK 52
// for nodemcu
// #define HEATER_PIN D0
// #define HFIRE_PIN D0
// #define MOTOR_F_PIN D0
// #define MOTOR_B_PIN D0
// #define FAN_PIN D0
// #define ALARM_PIN D0
// const int btn1 = D1;
// const int btn2 = D2;
// const int btn3 = 10;
// const int btn4 = 10;
// // TFT Display
// #define TFT_CS D3 // Change to D3 or any available pin
// #define TFT_RST -1 // Keep unchanged
// #define TFT_DC D4 // Keep unchanged
// #define TFT_MOSI D7 // Keep unchanged
// #define TFT_CLK D5 // Keep unchanged
// // SD Card Module
// #define SD_CS D8 // Keep unchanged
// #define SD_MOSI D7 // Keep unchanged
// #define SD_MISO D6 // MISO pin for SD card module
// #define SD_CLK D5 // Keep unchanged
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
OneButton button1(btn1, true);
OneButton button2(btn2, true);
OneButton button3(btn3, true);
OneButton button4(btn4, true);
#define DHTPIN A0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// Define thresholds
float Heater_ON;
float Heater_OFF;
float Bac_Heater_ON;
float Bac_Heater_OFF;
float Humi_ON;
float Humi_OFF;
float HT_Fan_ON;
float HH_Fan_ON;
float HT_Alarm_ON;
float HH_Alarm_ON;
float LT_Alarm_ON;
float LH_Alarm_ON;
float motor_off_minute;
float motor_running_second;
float ventilation_off_minute;
float ventilation_running_second;
int date;
// Motor timings
bool motor_forward = true;
bool motor_func_called = true;
bool motor_status = true;
// ventilation timings
bool ventilation_on;
unsigned long motor_start_time;
unsigned long ventilation_start_time;
unsigned long current_time;
// Button state flags
boolean btn1_clicked = false, btn1_double_clicked = false, btn1_long_clicked = false, btn1_long_pressing = false, btn1_long_clicked_stop = false;
boolean btn2_clicked = false, btn2_double_clicked = false, btn2_long_clicked = false, btn2_long_pressing = false, btn2_long_clicked_stop = false;
boolean btn3_clicked = false, btn3_double_clicked = false, btn3_long_clicked = false, btn3_long_pressing = false, btn3_long_clicked_stop = false;
boolean btn4_clicked = false, btn4_double_clicked = false, btn4_long_clicked = false, btn4_long_pressing = false, btn4_long_clicked_stop = false;
enum pageType { ROOT_MENU, SET_MENU };
enum pageType currPage = ROOT_MENU;
// Index for the current threshold being adjusted
int currentThreshold = 0;
const int NUM_THRESHOLDS = 17;
void readThresholdsFromSD() {
File dataFile = SD.open("value.txt");
if (dataFile) {
Heater_ON = dataFile.parseFloat();
Heater_OFF = dataFile.parseFloat();
Bac_Heater_ON = dataFile.parseFloat();
Bac_Heater_OFF = dataFile.parseFloat();
Humi_ON = dataFile.parseFloat();
Humi_OFF = dataFile.parseFloat();
HT_Fan_ON = dataFile.parseFloat();
HH_Fan_ON = dataFile.parseFloat();
HT_Alarm_ON = dataFile.parseFloat();
HH_Alarm_ON = dataFile.parseFloat();
LT_Alarm_ON = dataFile.parseFloat();
LH_Alarm_ON = dataFile.parseFloat();
motor_off_minute = dataFile.parseFloat();
motor_running_second = dataFile.parseFloat();
ventilation_off_minute = dataFile.parseFloat();
ventilation_running_second = dataFile.parseFloat();
date = dataFile.parseFloat();
dataFile.close();
Serial.println("Thresholds read from SD card.");
} else {
Serial.println("Error opening value.txt");
}
}
void writeThresholdsToSD() {
if (SD.exists("value.txt")) {
SD.remove("value.txt");}
File dataFile = SD.open("value.txt", FILE_WRITE);
if (dataFile) {
dataFile.print("Heater_ON = "); dataFile.print(Heater_ON); dataFile.print("\n");
dataFile.print("Heater_OFF = "); dataFile.print(Heater_OFF); dataFile.print("\n");
dataFile.print("Bac_Heater_ON = "); dataFile.print(Bac_Heater_ON); dataFile.print("\n");
dataFile.print("Bac_Heater_OFF = "); dataFile.print(Bac_Heater_OFF); dataFile.print("\n");
dataFile.print("Humi_ON = "); dataFile.print(Humi_ON); dataFile.print("\n");
dataFile.print("Humi_OFF = "); dataFile.print(Humi_OFF); dataFile.print("\n");
dataFile.print("HT_Fan_ON = "); dataFile.print(HT_Fan_ON); dataFile.print("\n");
dataFile.print("HH_Fan_ON = "); dataFile.print(HH_Fan_ON); dataFile.print("\n");
dataFile.print("HT_Alarm_ON = "); dataFile.print(HT_Alarm_ON); dataFile.print("\n");
dataFile.print("HH_Alarm_ON = "); dataFile.print(HH_Alarm_ON); dataFile.print("\n");
dataFile.print("LT_Alarm_ON = "); dataFile.print(LT_Alarm_ON); dataFile.print("\n");
dataFile.print("LH_Alarm_ON = "); dataFile.print(LH_Alarm_ON); dataFile.print("\n");
dataFile.print("motor_off_minute = "); dataFile.print(motor_off_minute); dataFile.print("\n");
dataFile.print("motor_running_second = "); dataFile.print(motor_running_second); dataFile.print("\n");
dataFile.print("ventilation_off_minute = "); dataFile.print(ventilation_off_minute); dataFile.print("\n");
dataFile.print("ventilation_running_second = "); dataFile.print(ventilation_running_second); dataFile.print("\n");
dataFile.print("date = "); dataFile.print(date); dataFile.print("\n");
dataFile.close();
Serial.println("Thresholds written to SD card.");
} else {
Serial.println("Error opening value.txt");
}
}
// for testing without sensor
// float temp=0;
// float hum=0;
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
tft.setTextSize(2);
tft.setTextColor(ILI9341_WHITE);
tft.fillScreen(ILI9341_BLACK);
pinMode(DHTPIN, INPUT);
pinMode(HEATER_PIN, OUTPUT);
pinMode(HFIRE_PIN, OUTPUT);
pinMode(FAN_PIN, OUTPUT);
pinMode(ALARM_PIN, OUTPUT);
pinMode(MOTOR_F_PIN, OUTPUT);
pinMode(MOTOR_B_PIN, OUTPUT);
// no need while using onebutton library
// pinMode(btn1, INPUT_PULLUP);
// pinMode(btn2, INPUT_PULLUP);
// pinMode(btn3, INPUT_PULLUP);
// pinMode(btn4, INPUT_PULLUP);
// link the button 1 functions.
button1.attachClick(click1);
button1.attachDoubleClick(doubleclick1);
button1.attachLongPressStart(longclick1);
button1.attachDuringLongPress(longpressing1);
button1.attachLongPressStop(longclickstop1);
// link the button 2 functions.
button2.attachClick(click2);
button2.attachDoubleClick(doubleclick2);
button2.attachLongPressStart(longclick2);
button2.attachDuringLongPress(longpressing2);
button2.attachLongPressStop(longclickstop2);
// link the button 3 functions.
button3.attachClick(click3);
button3.attachDoubleClick(doubleclick3);
button3.attachLongPressStart(longclick3);
button3.attachDuringLongPress(longpressing3);
button3.attachLongPressStop(longclickstop3);
// link the button 4 functions.
button4.attachClick(click4);
button4.attachDoubleClick(doubleclick4);
button4.attachLongPressStart(longclick4);
button4.attachDuringLongPress(longpressing4);
button4.attachLongPressStop(longclickstop4);
if (!SD.begin(SD_CS)) { // Adjust the pin according to your setup
Serial.println("SD card initialization failed!");
return;
}
// Read thresholds from SD card
readThresholdsFromSD();
dht.begin();
motor_start_time = millis();
ventilation_start_time = millis();
}
void loop() {
// if (Serial.available() > 0) {
// String input = Serial.readStringUntil('\n');
// Serial.print("Received input: ");
// Serial.println(input); // Print the received input for debugging
// // Handle temp input
// if (input.startsWith("t:")) {
// String tempValue = input.substring(2); // Remove "t: "
// temp = tempValue.toFloat();
// Serial.print("Temperature set to: ");
// Serial.println(temp);
// }
// // Handle hum input
// else if (input.startsWith("h:")) {
// String humiValue = input.substring(2); // Remove "h: "
// hum = humiValue.toFloat();
// Serial.print("Humidity set to: ");
// Serial.println(hum);
// }
// }
current_time = millis();
switch (currPage) {
case ROOT_MENU: page_RootMenu(); break;
case SET_MENU: page_SetMenu(); break;
default: page_RootMenu(); break;
}
}
void resetButtonStates() {
btn1_clicked = btn1_double_clicked = btn1_long_clicked = btn1_long_pressing = btn1_long_clicked_stop = false;
btn2_clicked = btn2_double_clicked = btn2_long_clicked = btn2_long_pressing = btn2_long_clicked_stop = false;
btn3_clicked = btn3_double_clicked = btn3_long_clicked = btn3_long_pressing = btn3_long_clicked_stop = false;
btn4_clicked = btn4_double_clicked = btn4_long_clicked = btn4_long_pressing = btn4_long_clicked_stop = false;
}
void displayRemainingTime(unsigned long timeInMillis) {
unsigned long hours = timeInMillis / 3600000;
unsigned long minutes = (timeInMillis % 3600000) / 60000;
unsigned long seconds = (timeInMillis % 60000) / 1000;
// Clear the previous text area
tft.fillRect(70, 100, 96, 16, ILI9341_RED);
tft.setCursor(10, 100);
tft.print("TIME:");
if (hours < 10) tft.print("0");
tft.print(hours);
tft.print(":");
if (minutes < 10) tft.print("0");
tft.print(minutes);
tft.print(":");
if (seconds < 10) tft.print("0");
tft.print(seconds);
}
void motor_working() {
unsigned long remainingTimeMillis = 0;
unsigned long motor_off = motor_off_minute * 60 * 1000;
unsigned long motor_running = motor_running_second * 1000;
if (current_time - motor_start_time <= motor_off) {
digitalWrite(MOTOR_F_PIN, LOW);
digitalWrite(MOTOR_B_PIN, LOW);
// Clear previous motor status text
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
tft.print("MOTOR: OFF ");
remainingTimeMillis = motor_off - (current_time - motor_start_time);
} else if (current_time - motor_start_time > motor_off && current_time - motor_start_time <= (motor_off + motor_running)) {
// Clear previous motor status text
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
if (motor_forward) {
digitalWrite(MOTOR_F_PIN, HIGH);
tft.print("MOTOR: Run F");
} else {
digitalWrite(MOTOR_B_PIN, HIGH);
tft.print("MOTOR: Run B");
}
remainingTimeMillis = (motor_off + motor_running) - (current_time - motor_start_time);
} else {
motor_start_time = millis();
motor_forward = !motor_forward;
remainingTimeMillis = 0; // Reset remaining time after transition
// Clear previous motor status text
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
tft.print("MOTOR: OFF ");
}
// Call this function with the appropriate remaining time
displayRemainingTime(remainingTimeMillis);
}
void ventilation_working() {
unsigned long ventilation_off = ventilation_off_minute * 60 * 1000;
unsigned long ventilation_running = ventilation_running_second * 1000;
if (current_time - ventilation_start_time <= ventilation_off) {
ventilation_on = false;
} else if (current_time - ventilation_start_time > ventilation_off && current_time - ventilation_start_time <= (ventilation_off + ventilation_running)) {
ventilation_on = true;
} else {
ventilation_start_time = millis();
}
}
void resetThresholds() {
Heater_ON = 35;
Heater_OFF = 40;
Bac_Heater_ON = 25;
Bac_Heater_OFF = 40;
Humi_ON = 60;
Humi_OFF = 70;
HT_Fan_ON = 45;
HH_Fan_ON = 75;
HT_Alarm_ON = 50;
HH_Alarm_ON = 80;
LT_Alarm_ON = 20;
LH_Alarm_ON = 40;
motor_off_minute = 1;
motor_running_second = 8;
ventilation_off_minute = 1;
ventilation_running_second = 8;
date = 1;
writeThresholdsToSD();
motor_start_time = millis();
ventilation_start_time = millis();
}
void page_RootMenu(void) {
tft.setTextSize(2);
resetButtonStates();
button1.tick();
button2.tick();
button3.tick();
button4.tick();
if (motor_func_called) {
motor_working();
}
ventilation_working();
float temp = dht.readTemperature();
float hum = dht.readHumidity();
tft.fillRect(70, 10, 96, 16, ILI9341_RED);
tft.setCursor(10, 10);
tft.print("TEMP: ");
tft.print(temp, 1);
tft.print(" C");
tft.fillRect(70, 40, 96, 16, ILI9341_RED);
tft.setCursor(10, 40);
tft.print("HUMI: ");
tft.print(hum, 1);
tft.print(" %");
// Temperature control
if (temp <= Heater_ON) {
digitalWrite(HEATER_PIN, HIGH);
tft.fillRect(240, 10, 80, 16, ILI9341_RED);
tft.setCursor(180, 10);
tft.print("HEAT: ON-I");
} else if (temp >= Heater_OFF) {
digitalWrite(HEATER_PIN, LOW);
tft.fillRect(240, 10, 80, 16, ILI9341_RED);
tft.setCursor(180, 10);
tft.print("HEAT: OFF");
}
if (temp <= Bac_Heater_ON) {
digitalWrite(BAC_HEATER_PIN, HIGH);
tft.fillRect(240, 10, 80, 16, ILI9341_RED);
tft.setCursor(180, 10);
tft.print("HEAT: ON-II");
} else if (temp >= Bac_Heater_OFF) {
digitalWrite(BAC_HEATER_PIN, LOW);
tft.fillRect(240, 10, 80, 16, ILI9341_RED);
tft.setCursor(180, 10);
tft.print("HEAT: OFF");
}
// Humidity control
if (hum <= Humi_ON) {
digitalWrite(HFIRE_PIN, HIGH);
tft.fillRect(240, 40, 50, 16, ILI9341_RED);
tft.setCursor(180, 40);
tft.print("HUMI: ON");
} else if (hum >= Humi_OFF) {
digitalWrite(HFIRE_PIN, LOW);
tft.fillRect(240, 40, 50, 16, ILI9341_RED);
tft.setCursor(180, 40);
tft.print("HUMI: OFF");
}
// Fan control
if (temp >= HT_Fan_ON || hum >= HH_Fan_ON || ventilation_on) {
digitalWrite(FAN_PIN, HIGH);
tft.fillRect(228, 70, 50, 16, ILI9341_RED);
tft.setCursor(180, 70);
tft.print("FAN: ON");
} else {
digitalWrite(FAN_PIN, LOW);
tft.fillRect(228, 70, 50, 16, ILI9341_RED);
tft.setCursor(180, 70);
tft.print("FAN: OFF");
}
// Alarm control
if (temp >= HT_Alarm_ON || hum >= HH_Alarm_ON || temp <= LT_Alarm_ON || hum <= LH_Alarm_ON) {
digitalWrite(ALARM_PIN, HIGH);
tft.fillRect(252, 100, 50, 16, ILI9341_RED);
tft.setCursor(180, 100);
tft.print("ALARM: ON");
} else {
digitalWrite(ALARM_PIN, LOW);
tft.fillRect(252, 100, 50, 16, ILI9341_RED);
tft.setCursor(180, 100);
tft.print("ALARM: OFF");
}
// Handle Button 2 long click for resetting thresholds
if (btn2_long_clicked) {
btn2_long_clicked = false;
resetThresholds();
// Clear the screen and display a reset message
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 16);
tft.print(" .....Reset....");
delay(500); // Show the reset message for a short time
tft.fillScreen(ILI9341_BLACK);
}
// Move to the selected page
if (btn1_long_clicked) {
currentThreshold = 0;
tft.fillScreen(ILI9341_BLACK);
currPage = SET_MENU;
return;
}
// Long pressing functionality
if (btn3_long_pressing) {
btn3_long_pressing = false;
motor_func_called = false;
digitalWrite(MOTOR_F_PIN, HIGH);
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
tft.print("MOTOR: Run F");
}
if (btn3_long_clicked_stop) {
btn3_long_clicked_stop = false;
motor_start_time = millis();
motor_forward = false;
motor_func_called = true;
}
if (btn4_long_pressing) {
btn4_long_pressing = false;
motor_func_called = false;
digitalWrite(MOTOR_B_PIN, HIGH);
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
tft.print("MOTOR: Run B");
}
if (btn4_long_clicked_stop) {
btn4_long_clicked_stop = false;
motor_start_time = millis();
motor_forward = true;
motor_func_called = true;
}
// Click functionality
if (btn3_clicked) {
btn3_clicked = false;
motor_func_called = false;
motor_start_time = millis();
if (motor_status) {
digitalWrite(MOTOR_F_PIN, HIGH);
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
tft.print("MOTOR: Run F");
motor_status = false;
} else {
digitalWrite(MOTOR_F_PIN, LOW);
digitalWrite(MOTOR_B_PIN, LOW);
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
tft.print("MOTOR: Off");
motor_status = true;
motor_func_called = true;
}
}
if (btn4_clicked) {
btn4_clicked = false;
motor_func_called = false;
motor_start_time = millis();
if (motor_status) {
digitalWrite(MOTOR_B_PIN, HIGH);
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
tft.print("MOTOR: Run B");
motor_status = false;
} else {
digitalWrite(MOTOR_B_PIN, LOW);
digitalWrite(MOTOR_F_PIN, LOW);
tft.fillRect(82, 70, 84, 16, ILI9341_RED);
tft.setCursor(10, 70);
tft.print("MOTOR: Off");
motor_status = true;
motor_func_called = true;
}
}
tft.fillRect(0, 127, tft.width(), 3 , ILI9341_WHITE);
tft.setTextSize(1);
tft.fillRect(56, 135, 40, tft.height() , ILI9341_RED);
tft.setCursor(10, 140);
tft.print("HEAT ON:");
tft.print(Heater_ON,1);tft.print(",");tft.print(Bac_Heater_ON,1);
tft.setCursor(10, 160);
tft.print("HUMI ON:");
tft.print(Humi_ON,1);
tft.setCursor(10, 180);
tft.print("HT_F_ON:");
tft.print(HT_Fan_ON,1);
tft.setCursor(10, 200);
tft.print("HT_A_ON:");
tft.print(HT_Alarm_ON,1);
tft.setCursor(10, 220);
tft.print("LT_A_ON:");
tft.print(LT_Alarm_ON,1);
tft.fillRect(162, 135, 40, tft.height() , ILI9341_RED);
tft.setCursor(110, 140);
tft.print("HEAT OFF:");
tft.print(Heater_OFF,1);tft.print(",");tft.print(Bac_Heater_OFF,1);
tft.setCursor(110, 160);
tft.print("HUMI OFF:");
tft.print(Humi_OFF,1);
tft.setCursor(110, 180);
tft.print("HH_F_ON :");
tft.print(HH_Fan_ON,1);
tft.setCursor(110, 200);
tft.print("HH_A_ON :");
tft.print(HH_Alarm_ON,1);
tft.setCursor(110, 220);
tft.print("LH_A_ON :");
tft.print(LH_Alarm_ON,1);
tft.fillRect(268, 135, 40, tft.height() , ILI9341_RED);
tft.setCursor(210, 140);
tft.print("MOTOR OFF:");
tft.print(motor_off_minute,0);
tft.print(" MIN");
tft.setCursor(210, 160);
tft.print("MOTOR ON:");
tft.print(motor_running_second,0);
tft.print(" SEC");
tft.setCursor(210, 180);
tft.print("VENT OFF:");
tft.print(ventilation_off_minute,0);
tft.print(" MIN");
tft.setCursor(210, 200);
tft.print("VENT ON:");
tft.print(ventilation_running_second,0);
tft.print(" SEC");
tft.setCursor(210, 220);
tft.print("DATE:");
tft.print(date);
}
void page_SetMenu(void) {
resetButtonStates();
digitalWrite(HEATER_PIN, LOW);
digitalWrite(BAC_HEATER_PIN, LOW);
digitalWrite(HFIRE_PIN, LOW);
digitalWrite(MOTOR_F_PIN, LOW);
digitalWrite(MOTOR_B_PIN, LOW);
digitalWrite(FAN_PIN, LOW);
digitalWrite(ALARM_PIN, LOW);
tft.setTextSize(2);
tft.setCursor(60, 0);
tft.print(">>SET_MENU<<");
// Update button states
button1.tick();
button2.tick();
button3.tick();
button4.tick();
displayCurrentThreshold();
if (btn3_clicked || btn3_long_pressing ) {
incrementThreshold();
btn3_clicked = false;
btn3_long_pressing = false;
tft.fillRect(0, 100, tft.width(), 24, ILI9341_BLACK);
}
if (btn4_clicked || btn4_long_pressing) {
decrementThreshold();
btn4_clicked = false;
btn4_long_pressing = false;
tft.fillRect(0, 100, tft.width(), 24, ILI9341_BLACK);
}
if (btn1_clicked) {
currentThreshold = (currentThreshold + 1) % NUM_THRESHOLDS;
btn1_clicked = false;
tft.fillRect(0, 50, tft.width(), 24, ILI9341_BLACK);
tft.fillRect(0, 100, tft.width(), 24, ILI9341_BLACK);
}
if (btn2_clicked) {
currentThreshold = (currentThreshold - 1 + NUM_THRESHOLDS) % NUM_THRESHOLDS; // Ensure wrapping correctly
btn2_clicked = false;
tft.fillRect(0, 50, tft.width(), 24, ILI9341_BLACK);
tft.fillRect(0, 100, tft.width(), 24, ILI9341_BLACK);
}
if (btn1_long_clicked) {
btn1_long_clicked = false;
// motor_start_time = millis();
// ventilation_start_time = millis();
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.print("....updated....");
delay(500);
tft.fillScreen(ILI9341_BLACK);
currPage = ROOT_MENU;
return;
}
// Keep a specific pace
// while (millis() - loopStartMs < 25) { delay(2); }
}
void displayCurrentThreshold() {
switch (currentThreshold) {
case 0: tft.setCursor(10,50); tft.print("ENTER HEATER ON:"); tft.setCursor(100,100); tft.print(Heater_ON, 1); break;
case 1: tft.setCursor(10,50); tft.print("ENTER HEATER OFF:"); tft.setCursor(100,100); tft.print(Heater_OFF, 1); break;
case 2: tft.setCursor(10,50); tft.print("ENTER BAC HEATER ON:"); tft.setCursor(100,100); tft.print(Bac_Heater_ON, 1); break;
case 3: tft.setCursor(10,50); tft.print("ENTER BAC HEATER OFF:"); tft.setCursor(100,100); tft.print(Bac_Heater_OFF, 1); break;
case 4: tft.setCursor(10,50); tft.print("ENTER HUMIDITY ON:"); tft.setCursor(100,100); tft.print(Humi_ON, 1); break;
case 5: tft.setCursor(10,50); tft.print("ENTER HUMIDITY OFF:"); tft.setCursor(100,100); tft.print(Humi_OFF, 1); break;
case 6: tft.setCursor(10,50); tft.print("ENTER HIGH TEMP FAN ON:"); tft.setCursor(100,100); tft.print(HT_Fan_ON, 1); break;
case 7: tft.setCursor(10,50); tft.print("ENTER HIGH HUMI FAN ON:"); tft.setCursor(100,100); tft.print(HH_Fan_ON, 1); break;
case 8: tft.setCursor(10,50); tft.print("ENTER HIGH TEMP ALARM ON:"); tft.setCursor(100,100); tft.print(HT_Alarm_ON, 1); break;
case 9: tft.setCursor(10,50); tft.print("ENTER HIGH HUMI ALARM ON:"); tft.setCursor(100,100); tft.print(HH_Alarm_ON, 1); break;
case 10: tft.setCursor(10,50); tft.print("ENTER LOW TEMP ALARM ON:"); tft.setCursor(100,100); tft.print(LT_Alarm_ON, 1); break;
case 11: tft.setCursor(10,50); tft.print("ENTER LOW HUMI ALARM ON:"); tft.setCursor(100,100); tft.print(LH_Alarm_ON, 1); break;
case 12: tft.setCursor(10,50); tft.print("MOTOR OFF PERIOD:"); tft.setCursor(100,100); tft.print(motor_off_minute,0); tft.print(" MIN"); break;
case 13: tft.setCursor(10,50); tft.print("MOTOR ON PERIOD:"); tft.setCursor(100,100); tft.print(motor_running_second,0); tft.print(" SEC"); break;
case 14: tft.setCursor(10,50); tft.print("VENTILATION OFF PERIOD:"); tft.setCursor(100,100); tft.print(ventilation_off_minute,0); tft.print(" MIN"); break;
case 15: tft.setCursor(10,50); tft.print("VENTILATION ON PERIOD:"); tft.setCursor(100,100); tft.print(ventilation_running_second,0); tft.print(" SEC"); break;
case 16: tft.setCursor(10,50); tft.print("Date:"); tft.setCursor(100,100); tft.print(date); break;
}
}
void incrementThreshold() {
switch (currentThreshold) {
case 0: if (Heater_ON < 99.8) {Heater_ON += 0.1;} break;
case 1: if (Heater_OFF < 99.8) {Heater_OFF += 0.1;} break;
case 2: if (Bac_Heater_ON < 99.8) {Bac_Heater_ON += 0.1;} break;
case 3: if (Bac_Heater_OFF < 99.8) {Bac_Heater_OFF += 0.1;} break;
case 4: if (Humi_ON < 99.8) {Humi_ON += 0.1;} break;
case 5: if (Humi_OFF < 99.8) {Humi_OFF += 0.1;} break;
case 6: if (HT_Fan_ON < 99.8) {HT_Fan_ON += 0.1;} break;
case 7: if (HH_Fan_ON < 99.8) {HH_Fan_ON += 0.1;} break;
case 8: if (HT_Alarm_ON < 99.8) {HT_Alarm_ON += 0.1;} break;
case 9: if (HH_Alarm_ON < 99.8) {HH_Alarm_ON += 0.1;} break;
case 10: if (LT_Alarm_ON < 99.8) {LT_Alarm_ON += 0.1;} break;
case 11: if (LH_Alarm_ON < 99.8) {LH_Alarm_ON += 0.1;} break;
case 12: if (motor_off_minute < 999) { motor_off_minute += 1;} break;
case 13: if (motor_running_second < 999) { motor_running_second += 1;} break;
case 14: if(ventilation_off_minute < 999) { ventilation_off_minute += 1;} break;
case 15: if(ventilation_running_second < 999) { ventilation_running_second += 1;} break;
case 16: if(date < 31) { date += 1;} break;
}
writeThresholdsToSD(); // Save to SD card after incrementing
}
void decrementThreshold() {
switch (currentThreshold) {
case 0: if (Heater_ON > 0) {Heater_ON -= 0.1;} break;
case 1: if (Heater_OFF > 0) {Heater_OFF -= 0.1;} break;
case 2: if (Bac_Heater_ON > 0) {Bac_Heater_ON -= 0.1;} break;
case 3: if (Bac_Heater_OFF > 0) {Bac_Heater_OFF -= 0.1;} break;
case 4: if (Humi_ON > 0) {Humi_ON -= 0.1;} break;
case 5: if (Humi_OFF > 0) {Humi_OFF -= 0.1;} break;
case 6: if (HT_Fan_ON > 0) {HT_Fan_ON -= 0.1;} break;
case 7: if (HH_Fan_ON > 0) {HH_Fan_ON -= 0.1;} break;
case 8: if (HT_Alarm_ON > 0) {HT_Alarm_ON -= 0.1;} break;
case 9: if (HH_Alarm_ON > 0) {HH_Alarm_ON -= 0.1;} break;
case 10: if (LT_Alarm_ON > 0) {LT_Alarm_ON -= 0.1;} break;
case 11: if (LH_Alarm_ON > 0) {LH_Alarm_ON -= 0.1;} break;
case 12: if (motor_off_minute > 0) { motor_off_minute -= 1;} break;
case 13: if (motor_running_second > 0) { motor_running_second -= 1;} break;
case 14: if(ventilation_off_minute > 0) { ventilation_off_minute -= 1;} break;
case 15: if(ventilation_running_second > 0) { ventilation_running_second -= 1;} break;
case 16: if(date > 1) { date -= 1;} break;
}
writeThresholdsToSD(); // Save to SD card after incrementing
}
// Callback functions for buttons
void click1() { btn1_clicked = true; }
void doubleclick1() { btn1_double_clicked = true; }
void longclick1() { btn1_long_clicked = true; }
void longpressing1() { btn1_long_pressing = true; }
void longclickstop1() { btn1_long_clicked_stop = true; }
void click2() { btn2_clicked = true; }
void doubleclick2() { btn2_double_clicked = true; }
void longclick2() { btn2_long_clicked = true; }
void longpressing2() { btn2_long_pressing = true; }
void longclickstop2() { btn2_long_clicked_stop = true; }
void click3() { btn3_clicked = true; }
void doubleclick3() { btn3_double_clicked = true; }
void longclick3() { btn3_long_clicked = true; }
void longpressing3() { btn3_long_pressing = true; }
void longclickstop3() { btn3_long_clicked_stop = true; }
void click4() { btn4_clicked = true; }
void doubleclick4() { btn4_double_clicked = true; }
void longclick4() { btn4_long_clicked = true; }
void longpressing4() { btn4_long_pressing = true; }
void longclickstop4() { btn4_long_clicked_stop = true; }