int DisChargingPump = 2; // Pin connected to Unloading Pump
int Solenoid = 3; // Pin connected to Solenoid
int HLSensor = 6 ; // Pin connected to High Level Sensor الاخضر
int LLSensor = 9; // Pin connected to Low Level Sensor الاسود
#include "RTClib.h"
RTC_DS3231 rtc;
#include <EEPROM.h> //RTC يتم استدعاء الميموري الموجودة في
#define X_EEPROM_ADDRESS 0
int X;
void setup() {
EEPROM.get(0, X);
// If not, initialize X to 0
if (X == -1) {
X = 0;
EEPROM.put(0, X);
// Print the current value of X
Serial.print("Current value of X: ");
Serial.println(X);
}
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
}
Serial.begin(9600);
pinMode(Solenoid, OUTPUT);
pinMode(HLSensor, INPUT_PULLUP);
pinMode(LLSensor, INPUT_PULLUP);
digitalWrite(DisChargingPump, LOW);
digitalWrite(Solenoid, LOW);
}
void loop() {
unsigned long currentMillis = millis();
unsigned long previousMillis = 0;
DateTime now = rtc.now();
int timehour = now.hour();
int timemin = now.minute();
int timesec = now.second();
// Check if it's time to execute the order
if (currentMillis - previousMillis >= 2000) {
previousMillis = currentMillis; // Save the last execution time
// Your order code
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
if (timehour == 16 && timemin == 55&& timesec == 0) { // يتم تخزين 1 في المتغير كل يوم الساعة الواحدة ظهرا
// Add 1 to X and display the updated value
X++;
if (X % 24 == 0) {
X = X / 24;
EEPROM.put(0, X);
// Print the new value of X
Serial.print("New value of X: ");
Serial.println(X);
}
}
if (timehour == 16 && timemin == 55 && timesec == 5) { // يتم تخزين 1 في المتغير كل يوم الساعة الواحدة ظهرا
// Add 1 to X and display the updated value
X++;
if (X % 24 == 0) {
X = X / 24;
EEPROM.put(0, X);
// Print the new value of X
Serial.print("New value of X: ");
Serial.println(X);
}
}
if (EEPROM.get(0, X) == 2){ // تبدا هذه العملية بعد اسبوع الساعة الواحدة ظهرا
if (digitalRead(LLSensor) == HIGH ){ // تفريغ
digitalWrite(DisChargingPump, HIGH);
Serial.print("ON ");
}
else {
digitalWrite(DisChargingPump, LOW);
X = 3 ;
EEPROM.put(0, X);
}
}
if (EEPROM.get(0, X) == 3) {
if(digitalRead(LLSensor) == LOW && digitalRead(HLSensor) == LOW ){ // الملي
digitalWrite(Solenoid, HIGH);
}
else if(digitalRead(LLSensor) == HIGH && digitalRead(HLSensor) == HIGH){
digitalWrite(Solenoid, LOW);
X = 0 ; // بعد عملية الملي و قراءة الاتنين سينسور ان الخزان ملي ارجع قيمة المتغير بتاعي بصفر علشان البامبات ترجع تشتغل
EEPROM.put(0, X);
// Print the new value of X
Serial.print("New value of X: ");
Serial.println(X);
}
}
}