#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <RTClib.h>
#include <EEPROM.h>
#define role1 6
#define role2 7
#define role3 8
#define rolekapat1 10
#define rolekapat2 11
#define rolekapat3 12
#define nemSensoru1 A6
#define nemSensoru2 A7
LiquidCrystal_I2C lcd(0x27, 20, 4); // 20x4 LCD
RTC_DS1307 RTC;
// Keypad configuration
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the keymap
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Connect keypad rows and columns
byte colPins[COLS] = {5, 4, 3, 2};
byte rowPins[ROWS] = {9, A1, A2, A3};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int menuIndex = -1;
int AltmenuIndex = -1;
String inputString = "";
static bool prevRoleKapat1State = LOW;
static bool prevRoleKapat2State = LOW;
static bool prevRoleKapat3State = LOW;
// EEPROM addresses
const int relay1TimesAddress = 0;
const int relay2TimesAddress = 12;
const int relay3TimesAddress = 24;
const int nemSensoru1Adress = 36;
const int nemSensoru2Adress = 38;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(role1, OUTPUT);
pinMode(role2, OUTPUT);
pinMode(role3, OUTPUT);
pinMode(rolekapat1, INPUT);
pinMode(rolekapat2, INPUT);
pinMode(rolekapat3, INPUT);
pinMode(nemSensoru1, INPUT);
pinMode(nemSensoru2, INPUT);
RTC.begin();
// Initialize default values if EEPROM is empty
if (EEPROM.read(relay1TimesAddress) == 255) {
// Default times for relays
int defaultTimes1[3][2] = {{8, 0}, {12, 0}, {18, 0}};
int defaultTimes2[3][2] = {{6, 0}, {14, 0}, {20, 0}};
int defaultTimes3[3][2] = {{7, 0}, {13, 0}, {19, 0}};
for (int i = 0; i < 3; i++) {
EEPROM.put(relay1TimesAddress + (i * 4), defaultTimes1[i][0]);
EEPROM.put(relay1TimesAddress + (i * 4) + 2, defaultTimes1[i][1]);
EEPROM.put(relay2TimesAddress + (i * 4), defaultTimes2[i][0]);
EEPROM.put(relay2TimesAddress + (i * 4) + 2, defaultTimes2[i][1]);
EEPROM.put(relay3TimesAddress + (i * 4), defaultTimes3[i][0]);
EEPROM.put(relay3TimesAddress + (i * 4) + 2, defaultTimes3[i][1]);
}
}
// Default moisture thresholds
int nemicin1 = 500;
int nemicin2 = 600;
EEPROM.put(nemSensoru1Adress, nemicin1);
EEPROM.put(nemSensoru2Adress, nemicin2);
}
void Control() {
DateTime nowRtc = RTC.now();
static bool zaman1 = true;
static bool zaman2 = true;
static bool zaman3 = true;
bool currentRoleKapat1State = digitalRead(rolekapat1);
bool currentRoleKapat2State = digitalRead(rolekapat2);
bool currentRoleKapat3State = digitalRead(rolekapat3);
// Read times from EEPROM
int relay1Times[3][2], relay2Times[3][2], relay3Times[3][2];
for (int i = 0; i < 3; i++) {
EEPROM.get(relay1TimesAddress + (i * 4), relay1Times[i][0]);
EEPROM.get(relay1TimesAddress + (i * 4) + 2, relay1Times[i][1]);
EEPROM.get(relay2TimesAddress + (i * 4), relay2Times[i][0]);
EEPROM.get(relay2TimesAddress + (i * 4) + 2, relay2Times[i][1]);
EEPROM.get(relay3TimesAddress + (i * 4), relay3Times[i][0]);
EEPROM.get(relay3TimesAddress + (i * 4) + 2, relay3Times[i][1]);
}
// Read moisture thresholds
int nemicin1, nemicin2;
EEPROM.get(nemSensoru1Adress, nemicin1);
EEPROM.get(nemSensoru2Adress, nemicin2);
// Current time
int currentHour = nowRtc.hour();
int currentMinute = nowRtc.minute();
int currentSecond = nowRtc.second();
// Read moisture sensors
int sensor1 = analogRead(nemSensoru1);
int sensor2 = analogRead(nemSensoru2);
// Display sensor values for debugging (optional)
lcd.setCursor(0, 2);
lcd.print("S1:");
lcd.print(sensor1);
lcd.print(" S2:");
lcd.print(sensor2);
lcd.print(" ");
// Moisture-based control - PRIMARY CONTROL
// Sensor 1 controls Relay 1
if (sensor1 >= nemicin1) { // Soil is wet enough
if (digitalRead(role1) == HIGH) { // If relay is ON, turn it OFF
digitalWrite(role1, LOW);
zaman1 = true;
lcd.setCursor(0, 0);
lcd.print("Soil1 WET - Relay1 OFF");
}
} else { // Soil is dry
if (zaman1 && digitalRead(role1) == LOW) { // If relay is OFF and allowed to turn ON
digitalWrite(role1, HIGH);
zaman1 = false;
lcd.setCursor(0, 0);
lcd.print("Soil1 DRY - Relay1 ON ");
}
}
// Sensor 2 controls Relay 2
if (sensor2 >= nemicin2) { // Soil is wet enough
if (digitalRead(role2) == HIGH) { // If relay is ON, turn it OFF
digitalWrite(role2, LOW);
zaman2 = true;
lcd.setCursor(0, 0);
lcd.print("Soil2 WET - Relay2 OFF");
}
} else { // Soil is dry
if (zaman2 && digitalRead(role2) == LOW) { // If relay is OFF and allowed to turn ON
digitalWrite(role2, HIGH);
zaman2 = false;
lcd.setCursor(0, 0);
lcd.print("Soil2 DRY - Relay2 ON ");
}
}
// Time-based control - SECONDARY CONTROL (only if moisture control hasn't activated)
for (int i = 0; i < 3; i++) {
// Relay 1 - Only activate if moisture control hasn't already
if (relay1Times[i][0] == currentHour && relay1Times[i][1] == currentMinute && currentSecond == 0) {
if (zaman1 && digitalRead(role1) == LOW) {
digitalWrite(role1, HIGH);
zaman1 = false;
lcd.setCursor(0, 0);
lcd.print("Time ON - Relay1 ON ");
}
break;
}
// Relay 2 - Only activate if moisture control hasn't already
if (relay2Times[i][0] == currentHour && relay2Times[i][1] == currentMinute && currentSecond == 0) {
if (zaman2 && digitalRead(role2) == LOW) {
digitalWrite(role2, HIGH);
zaman2 = false;
lcd.setCursor(0, 0);
lcd.print("Time ON - Relay2 ON ");
}
break;
}
}
// Manual relay control - OVERRIDE
if (currentRoleKapat1State == HIGH && prevRoleKapat1State == LOW) {
digitalWrite(role1, LOW);
zaman1 = true;
lcd.setCursor(0, 0);
lcd.print("Manual - Relay1 OFF");
}
if (currentRoleKapat2State == HIGH && prevRoleKapat2State == LOW) {
digitalWrite(role2, LOW);
zaman2 = true;
lcd.setCursor(0, 0);
lcd.print("Manual - Relay2 OFF");
}
if (currentRoleKapat3State == HIGH && prevRoleKapat3State == LOW) {
digitalWrite(role3, LOW);
zaman3 = true;
lcd.setCursor(0, 0);
lcd.print("Manual - Relay3 OFF");
}
prevRoleKapat1State = currentRoleKapat1State;
prevRoleKapat2State = currentRoleKapat2State;
prevRoleKapat3State = currentRoleKapat3State;
}
void loop() {
Control();
char key = keypad.getKey();
if (key >= '0' && key <= '9') {
inputString += key;
} else if (key == 'A') { // Cycle through main menu options
menuIndex = (menuIndex + 1) % 4;
displayMenu();
inputString = "";
} else if (key == 'B') { // Cycle through submenu options
AltmenuIndex = (AltmenuIndex + 1) % 15; // Now we have more submenus
AltdisplayMenu();
inputString = "";
} else if (key == '*') { // Add a dot in the input
inputString += ".";
} else if (key == 'D') { // Confirm input and save to EEPROM
handleInput();
}
// Display the input on the screen
lcd.setCursor(0, 3);
lcd.print("Input: ");
lcd.setCursor(7, 3);
lcd.print(inputString);
}
void displayMenu() {
lcd.clear();
switch(menuIndex) {
case 0:
lcd.setCursor(0, 0);
lcd.print("Relay Time Settings");
lcd.setCursor(0, 1);
lcd.print("Submenu 1-9");
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("Date/Time Settings");
lcd.setCursor(0, 1);
lcd.print("Submenu 10-11");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("Humidity Settings");
lcd.setCursor(0, 1);
lcd.print("Submenu 12-13");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("Current Date/Time");
lcd.setCursor(0, 1);
lcd.print("Submenu 14");
AltdisplayMenu();
break;
}
}
void handleInput() {
if (menuIndex == 0) { // Relay Time Settings
if (AltmenuIndex >= 0 && AltmenuIndex <= 2) { // Relay1 times
int timeIndex = AltmenuIndex;
lcd.clear();
int hour = inputString.substring(0, 2).toInt();
int minute = inputString.substring(3, 5).toInt();
EEPROM.put(relay1TimesAddress + (timeIndex * 4), hour);
EEPROM.put(relay1TimesAddress + (timeIndex * 4) + 2, minute);
lcd.setCursor(0, 2);
lcd.print("Relay1 Time ");
lcd.print(timeIndex + 1);
lcd.print(" Saved:");
lcd.setCursor(0, 3);
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
}
else if (AltmenuIndex >= 3 && AltmenuIndex <= 5) { // Relay2 times
int timeIndex = AltmenuIndex - 3;
lcd.clear();
int hour = inputString.substring(0, 2).toInt();
int minute = inputString.substring(3, 5).toInt();
EEPROM.put(relay2TimesAddress + (timeIndex * 4), hour);
EEPROM.put(relay2TimesAddress + (timeIndex * 4) + 2, minute);
lcd.setCursor(0, 2);
lcd.print("Relay2 Time ");
lcd.print(timeIndex + 1);
lcd.print(" Saved:");
lcd.setCursor(0, 3);
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
}
else if (AltmenuIndex >= 6 && AltmenuIndex <= 8) { // Relay3 times
int timeIndex = AltmenuIndex - 6;
lcd.clear();
int hour = inputString.substring(0, 2).toInt();
int minute = inputString.substring(3, 5).toInt();
EEPROM.put(relay3TimesAddress + (timeIndex * 4), hour);
EEPROM.put(relay3TimesAddress + (timeIndex * 4) + 2, minute);
lcd.setCursor(0, 2);
lcd.print("Relay3 Time ");
lcd.print(timeIndex + 1);
lcd.print(" Saved:");
lcd.setCursor(0, 3);
lcd.print(hour);
lcd.print(":");
lcd.print(minute);
}
}
else if (menuIndex == 1) { // Date/Time Settings
if (AltmenuIndex == 9) { // RTC Date
int day = inputString.substring(0, 2).toInt();
int month = inputString.substring(3, 5).toInt();
int year = inputString.substring(6, 10).toInt();
DateTime now = RTC.now();
RTC.adjust(DateTime(year, month, day, now.hour(), now.minute(), now.second()));
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("Date saved:");
lcd.setCursor(0, 3);
lcd.print(day);
lcd.print('/');
lcd.print(month);
lcd.print('/');
lcd.print(year);
}
else if (AltmenuIndex == 10) { // RTC Time
int hour = inputString.substring(0, 2).toInt();
int minute = inputString.substring(3, 5).toInt();
DateTime now = RTC.now();
RTC.adjust(DateTime(now.year(), now.month(), now.day(), hour, minute, 0));
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("Time saved:");
lcd.setCursor(0, 3);
lcd.print(hour);
lcd.print(':');
lcd.print(minute);
}
}
else if (menuIndex == 2) { // Humidity Settings
if (AltmenuIndex == 11) { // Humidity 1
lcd.clear();
int hum1 = inputString.toInt();
EEPROM.put(nemSensoru1Adress, hum1);
lcd.setCursor(0, 2);
lcd.print("Humidity1 saved:");
lcd.setCursor(0, 3);
lcd.print(hum1);
}
else if (AltmenuIndex == 12) { // Humidity 2
lcd.clear();
int hum2 = inputString.toInt();
EEPROM.put(nemSensoru2Adress, hum2);
lcd.setCursor(0, 2);
lcd.print("Humidity2 saved:");
lcd.setCursor(0, 3);
lcd.print(hum2);
}
}
inputString = "";
}
void AltdisplayMenu() {
lcd.clear();
if (menuIndex == 0) { // Relay Time Settings
if (AltmenuIndex >= 0 && AltmenuIndex <= 2) { // Relay1 times
int timeIndex = AltmenuIndex;
int hour, minute;
EEPROM.get(relay1TimesAddress + (timeIndex * 4), hour);
EEPROM.get(relay1TimesAddress + (timeIndex * 4) + 2, minute);
lcd.setCursor(0, 0);
lcd.print("Relay1 Time ");
lcd.print(timeIndex + 1);
lcd.setCursor(0, 1);
lcd.print("Current: ");
lcd.print(hour);
lcd.print(":");
if (minute < 10) lcd.print("0");
lcd.print(minute);
}
else if (AltmenuIndex >= 3 && AltmenuIndex <= 5) { // Relay2 times
int timeIndex = AltmenuIndex - 3;
int hour, minute;
EEPROM.get(relay2TimesAddress + (timeIndex * 4), hour);
EEPROM.get(relay2TimesAddress + (timeIndex * 4) + 2, minute);
lcd.setCursor(0, 0);
lcd.print("Relay2 Time ");
lcd.print(timeIndex + 1);
lcd.setCursor(0, 1);
lcd.print("Current: ");
lcd.print(hour);
lcd.print(":");
if (minute < 10) lcd.print("0");
lcd.print(minute);
}
else if (AltmenuIndex >= 6 && AltmenuIndex <= 8) { // Relay3 times
int timeIndex = AltmenuIndex - 6;
int hour, minute;
EEPROM.get(relay3TimesAddress + (timeIndex * 4), hour);
EEPROM.get(relay3TimesAddress + (timeIndex * 4) + 2, minute);
lcd.setCursor(0, 0);
lcd.print("Relay3 Time ");
lcd.print(timeIndex + 1);
lcd.setCursor(0, 1);
lcd.print("Current: ");
lcd.print(hour);
lcd.print(":");
if (minute < 10) lcd.print("0");
lcd.print(minute);
}
}
else if (menuIndex == 1) { // Date/Time Settings
if (AltmenuIndex == 9) {
lcd.setCursor(0, 0);
lcd.print("Set Date (DD.MM.YYYY)");
}
else if (AltmenuIndex == 10) {
lcd.setCursor(0, 0);
lcd.print("Set Time (HH:MM)");
}
}
else if (menuIndex == 2) { // Humidity Settings
if (AltmenuIndex == 11) {
int hum1;
EEPROM.get(nemSensoru1Adress, hum1);
lcd.setCursor(0, 0);
lcd.print("Humidity1 Threshold");
lcd.setCursor(0, 1);
lcd.print("Current: ");
lcd.print(hum1);
}
else if (AltmenuIndex == 12) {
int hum2;
EEPROM.get(nemSensoru2Adress, hum2);
lcd.setCursor(0, 0);
lcd.print("Humidity2 Threshold");
lcd.setCursor(0, 1);
lcd.print("Current: ");
lcd.print(hum2);
}
}
else if (menuIndex == 3) { // Current Date/Time
DateTime now = RTC.now();
lcd.setCursor(0, 0);
lcd.print("Date: ");
lcd.print(now.day());
lcd.print('/');
lcd.print(now.month());
lcd.print('/');
lcd.print(now.year());
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(now.hour());
lcd.print(':');
if (now.minute() < 10) lcd.print('0');
lcd.print(now.minute());
lcd.print(':');
if (now.second() < 10) lcd.print('0');
lcd.print(now.second());
}
inputString = "";
}
/*#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <RTClib.h>
#include <EEPROM.h>
#define role1 6
#define role2 7
#define role3 8
#define role4 12
#define role5 13
#define rolekapat1 9
#define rolekapat2 10
#define rolekapat3 11
#define nemSensoru1 A6
#define nemSensoru2 A7
LiquidCrystal_I2C lcd(0x27, 20, 4); // 20x4 LCD
RTC_DS1307 RTC;
// Keypad configuration
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
// Define the keymap
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
// Connect rows of the keypad to these Pico GPIO pins
byte colPins[COLS] = {5, 4, 3, 2};
byte rowPins[ROWS] = {9, A1, A2, A3}; // Ensure these are correct GPIO pins for analog
// Create the keypad object
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int menuIndex = -1;
int AltmenuIndex = -1;
String inputString = "";
static bool prevRoleKapat1State = LOW; // Store previous state of the button
static bool prevRoleKapat2State = LOW;
static bool prevRoleKapat3State = LOW;
// EEPROM addresses
const int ekimZamaniAddress = 0;
const int besin1ZamaniAddressSaat = 2;
const int besin1ZamaniAddressDakika = 4;
const int besin1ZamaniAddressSaniye = 6;
const int besin2ZamaniAddressSaat = 8;
const int besin2ZamaniAddressDakika = 10;
const int besin2ZamaniAddressSaniye = 12;
const int besin3ZamaniAddressSaat = 14;
const int besin3ZamaniAddressDakika = 16;
const int besin3ZamaniAddressSaniye = 18;
const int nemSensoru1Adress = 20;//999
const int nemSensoru2Adress = 22;//999
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(role1, OUTPUT);
pinMode(role2, OUTPUT);
pinMode(role3, OUTPUT);
pinMode(role4, OUTPUT);
pinMode(role5, OUTPUT);
pinMode(rolekapat1, INPUT);
pinMode(rolekapat2, INPUT);
pinMode(rolekapat3, INPUT);
pinMode(nemSensoru1, INPUT);
pinMode(nemSensoru2, INPUT);
RTC.begin();
int nemicin1=500;
EEPROM.put(nemSensoru1Adress, nemicin1);
int nemicin2=600;
EEPROM.put(nemSensoru2Adress, nemicin2);
}
void Control() {
DateTime nowRtc = RTC.now(); // Get current date and time
static bool zaman1 = true; // Use static to retain state across function calls
static bool zaman2 = true;
static bool zaman3 = true;
bool currentRoleKapat1State = digitalRead(rolekapat1);
bool currentRoleKapat2State = digitalRead(rolekapat2);
bool currentRoleKapat3State = digitalRead(rolekapat3);
// Read feeding times from EEPROM
int saat1, dakika1,saniye1;
EEPROM.get(besin1ZamaniAddressSaat, saat1);
EEPROM.get(besin1ZamaniAddressDakika, dakika1);
EEPROM.get(besin1ZamaniAddressSaniye, saniye1);
int saat2, dakika2,saniye2;
EEPROM.get(besin2ZamaniAddressSaat, saat2);
EEPROM.get(besin2ZamaniAddressDakika, dakika2);
EEPROM.get(besin2ZamaniAddressSaniye, saniye2);
int saat3, dakika3,saniye3;
EEPROM.get(besin3ZamaniAddressSaat, saat3);
EEPROM.get(besin3ZamaniAddressDakika, dakika3);
EEPROM.get(besin3ZamaniAddressSaniye, saniye3);
int nemicin1;
EEPROM.get(nemSensoru1Adress, nemicin1);
int nemicin2;
EEPROM.get(nemSensoru2Adress, nemicin2);
// Get current hour and minute
int ControlSaat = nowRtc.hour();
int ControlDakika = nowRtc.minute();
int ControlSaniye = nowRtc.second();
int sensor1 = analogRead(nemSensoru1);
int sensor2 = analogRead(nemSensoru2);
// Time-based relay control
if (saat1 == ControlSaat && dakika1 == ControlDakika&&ControlSaniye==0) {
if (zaman1) {
digitalWrite(role1, HIGH);
zaman1 = false;
Serial.print("tetik");
}
} else if (saat2 == ControlSaat && dakika2 == ControlDakika&&ControlSaniye==0) {
if (zaman2) {
digitalWrite(role2, HIGH);
zaman2 = false;
}
} else if (saat3 == ControlSaat && dakika3 == ControlDakika&&ControlSaniye==0) {
if (zaman3) {
digitalWrite(role3, HIGH);
zaman3 = false;
}
}
// Sensor-based relay control
if (sensor1 >= nemicin1) {
digitalWrite(role4, HIGH);
zaman1 = false; // Ensure the relay stays on
} else if (sensor1 <= nemicin1) {
digitalWrite(role4, LOW);
zaman1 = true; // Allow relay to be activated next time
}
if (sensor2 >= nemicin2) {
digitalWrite(role5, HIGH);
zaman2 = false; // Ensure the relay stays on
} else if (sensor2 <= nemicin2) {
digitalWrite(role5, LOW);
zaman2 = true; // Allow relay to be activated next time
}
// Ensure relays are turned off if specific conditions are met
if (currentRoleKapat1State == HIGH && prevRoleKapat1State == LOW) {
digitalWrite(role1, LOW);
zaman1 = true; // Allow relay to be activated next time
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(zaman1);
}
if (currentRoleKapat2State == HIGH && prevRoleKapat2State == LOW) {
digitalWrite(role2, LOW);
zaman2 = true; // Allow relay to be activated next time
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(zaman2);
}
if (currentRoleKapat3State == HIGH && prevRoleKapat3State == LOW) {
digitalWrite(role3, LOW);
zaman3 = true; // Allow relay to be activated next time
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(zaman3);
}
prevRoleKapat1State = currentRoleKapat1State;
prevRoleKapat2State = currentRoleKapat2State;
prevRoleKapat3State = currentRoleKapat3State;
}
void loop() {
Control();
// lcd.clear();
// int sensor1= analogRead(nemSensoru1);
// lcd.setCursor(0, 0);
// lcd.print(sensor1);
// int sensor2= analogRead(nemSensoru2);
// lcd.setCursor(0, 1);
// lcd.print(sensor2);
char key = keypad.getKey();
if (key >= '0' && key <= '9') {
inputString += key;
} else if (key == 'A') { // Cycle through main menu options
menuIndex = (menuIndex + 1) % 4; // Assuming 3 main menu options
displayMenu();
inputString = ""; // Clear input string when switching menu
} else if (key == 'B') { // Cycle through submenu options
AltmenuIndex = (AltmenuIndex + 1) % 4; // Assuming 4 submenu options
AltdisplayMenu();
inputString = ""; // Clear input string when switching submenu
} else if (key == '*') { // Add a dot in the input
inputString += ".";
} else if (key == 'D') { // Confirm input and save to EEPROM
handleInput();
}
// Display the input on the screen
lcd.setCursor(0, 3);
lcd.print("Input: ");
lcd.setCursor(7, 3);
lcd.print(inputString);
}
void displayMenu() {
lcd.clear();
switch(menuIndex) {
case 0:
lcd.setCursor(0, 0);
lcd.print("Besin/Sulama Ayari");
lcd.setCursor(0, 1);
lcd.print("Alt Menu 4");
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("Tarih Saat Ayari");
lcd.setCursor(0, 1);
lcd.print("Alt Menu 3");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("nem ayarlari");
lcd.setCursor(0, 1);
lcd.print("Alt Menu 3");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("Tarih Saat");
lcd.setCursor(0, 1);
lcd.print("Alt Menu 4");
AltdisplayMenu();
break;
}
}
void handleInput() {
if(menuIndex == 0 && AltmenuIndex == 0) { // "Dikim Ayi"
lcd.clear();
int month = inputString.toInt();
EEPROM.put(ekimZamaniAddress, month);
lcd.setCursor(0, 2);
lcd.print("Ay kaydedildi: ");
lcd.print(month);
} else if(menuIndex == 0 && AltmenuIndex == 1) { // "Besleme Saati 1"
lcd.clear();
int saat1 = inputString.substring(0, 2).toInt();
int dakika1 = inputString.substring(3, 5).toInt();
EEPROM.put(besin1ZamaniAddressSaat, saat1);
EEPROM.put(besin1ZamaniAddressDakika, dakika1);
lcd.setCursor(0, 2);
lcd.print("Besleme 1 Kaydedildi:");
lcd.setCursor(0, 3);
lcd.print(saat1);
lcd.print(":");
lcd.print(dakika1);
} else if(menuIndex == 0 && AltmenuIndex == 2) { // "Besleme Saati 2"
lcd.clear();
int saat2 = inputString.substring(0, 2).toInt();
int dakika2 = inputString.substring(3, 5).toInt();
EEPROM.put(besin2ZamaniAddressSaat, saat2);
EEPROM.put(besin2ZamaniAddressDakika, dakika2);
lcd.setCursor(0, 2);
lcd.print("Besleme 2 Kaydedildi:");
lcd.setCursor(0, 3);
lcd.print(saat2);
lcd.print(":");
lcd.print(dakika2);
} else if(menuIndex == 0 && AltmenuIndex == 3) { // "Besleme Saati 3"
lcd.clear();
int saat3 = inputString.substring(0, 2).toInt();
int dakika3 = inputString.substring(3, 5).toInt();
EEPROM.put(besin3ZamaniAddressSaat, saat3);
EEPROM.put(besin3ZamaniAddressDakika, dakika3);
lcd.setCursor(0, 2);
lcd.print("Besleme 3 Kaydedildi:");
lcd.setCursor(0, 3);
lcd.print(saat3);
lcd.print(":");
lcd.print(dakika3);
} else if(menuIndex == 1 && AltmenuIndex == 0) { // "RTC Tarih Ayarı"
int day = inputString.substring(0, 2).toInt();
int month = inputString.substring(3, 5).toInt();
int year = inputString.substring(6, 10).toInt();
DateTime now = RTC.now();
RTC.adjust(DateTime(year, month, day, now.hour(), now.minute(), now.second()));
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("Tarih kaydedildi:");
lcd.setCursor(0, 3);
lcd.print(day);
lcd.print('/');
lcd.print(month);
lcd.print('/');
lcd.print(year);
} else if(menuIndex == 1 && AltmenuIndex == 1) { // "RTC Saat Ayarı"
int hour = inputString.substring(0, 2).toInt();
int minute = inputString.substring(3, 5).toInt();
DateTime now = RTC.now();
RTC.adjust(DateTime(now.year(), now.month(), now.day(), hour, minute, 0));
lcd.clear();
lcd.setCursor(0, 2);
lcd.print("Saat kaydedildi:");
lcd.setCursor(0, 3);
lcd.print(hour);
lcd.print(':');
lcd.print(minute);
} else if(menuIndex == 2 && AltmenuIndex == 0) { // nem 1
lcd.clear();
int nem1 = inputString.toInt();
EEPROM.put(nemSensoru1Adress, nem1);
lcd.setCursor(0, 2);
lcd.print("Nem 1 kaydedildi:");
lcd.setCursor(0, 3);
lcd.print(nem1);
} else if(menuIndex == 2 && AltmenuIndex == 1) { // nem 2
lcd.clear();
int nem2 = inputString.toInt();
EEPROM.put(nemSensoru2Adress, nem2);
lcd.setCursor(0, 2);
lcd.print("Nem 2 kaydedildi:");
lcd.setCursor(0, 3);
lcd.print(nem2);
}
inputString = ""; // Clear input after handling
}
void AltdisplayMenu() {
lcd.clear();
if(menuIndex == 0) { // Besin/Sulama AltMenu Ayarı
switch(AltmenuIndex) {
case 0:
lcd.setCursor(0, 0);
lcd.print("Dikim Ayi");
int month;
EEPROM.get(ekimZamaniAddress, month);
lcd.setCursor(0, 1);
lcd.print("Ay: ");
lcd.print(month);
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("Besleme Saati 1");
int saat1, dakika1;
EEPROM.get(besin1ZamaniAddressSaat, saat1);
EEPROM.get(besin1ZamaniAddressDakika, dakika1);
lcd.setCursor(0, 1);
lcd.print("Saat: ");
lcd.print(saat1);
lcd.print(":");
lcd.print(dakika1);
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("Besleme Saati 2");
int saat2, dakika2;
EEPROM.get(besin2ZamaniAddressSaat, saat2);
EEPROM.get(besin2ZamaniAddressDakika, dakika2);
lcd.setCursor(0, 1);
lcd.print("Saat: ");
lcd.print(saat2);
lcd.print(":");
lcd.print(dakika2);
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("Besleme Saati 3");
int saat3, dakika3;
EEPROM.get(besin3ZamaniAddressSaat, saat3);
EEPROM.get(besin3ZamaniAddressDakika, dakika3);
lcd.setCursor(0, 1);
lcd.print("Saat: ");
lcd.print(saat3);
lcd.print(":");
lcd.print(dakika3);
break;
case 4:
lcd.setCursor(0, 0);
lcd.print("Nem sensoru 1");
int nem1;
EEPROM.get(nemSensoru1Adress, nem1);
lcd.setCursor(0, 1);
lcd.print("Nem: ");
lcd.print(nem1);
break;
case 5:
lcd.setCursor(0, 0);
lcd.print("Nem sensoru 2");
int nem2;
EEPROM.get(nemSensoru2Adress, nem2);
lcd.setCursor(0, 1);
lcd.print("Nem: ");
lcd.print(nem2);
break;
}
} else if(menuIndex == 1) { // Tarih Ayarı AltMenu
switch(AltmenuIndex) {
case 0:
lcd.setCursor(0, 0);
lcd.print("RTC Tarih Ayari");
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("RTC Saat Ayari");
break;
}
} else if(menuIndex == 2) { // nem
switch(AltmenuIndex) {
case 0:
lcd.setCursor(0, 0);
lcd.print("Nem ayari 1");
int nem1;
EEPROM.get(nemSensoru1Adress, nem1);
lcd.setCursor(0, 1);
lcd.print("Nem: ");
lcd.print(nem1);
break;
case 1:
lcd.setCursor(0, 0);
lcd.print("Nem ayari 2");
int nem2;
EEPROM.get(nemSensoru2Adress, nem2);
lcd.setCursor(0, 1);
lcd.print("Nem: ");
lcd.print(nem2);
break;
}
}
inputString = ""; // Clear input after handling
}
*/