Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --------------------- ZONE COMMAND HV TACO ---------------------
- // ---------------------4 ZONE CONTROL BOARD-------------------
- // ------------------------I2C LCD DISPLAY---------------------
- // --------------------4 USER INPUT BUTTONS--------------------
- // -------------------DESIGNED AND PROGRAMMED BY:--------------
- // --------------------------COREY EARL-------------------------
- // ----------------REVISION 4.2 (Sept 6th, 2021)----------------
- // ----------------All Zones Appear to Function----------------
- // ---------------------More Testing Needed--------------------
- //----------------Ready for on-site BETA testing---------------
- //----------------------------FEATURES:-----------------------------
- //-----------------Easy to deactivate/activate each zone------------
- //----------------Easy trigger point setting per zone---------------
- //-----------User Adjustable and Auto-Adjustable Pump Times---------
- //----Also able to Operate Without Sensors on a ~24hr Pump Cycle----
- //--------------------------ISSUES:---------------------------------
- //-------EEPROM not working right, more testing needed--------
- //--------------------------------------------------------
- // Libraries
- #include <EEPROM.h>
- #include <LiquidCrystal_I2C.h>
- #include <Wire.h>
- LiquidCrystal_I2C lcd(0x27, 20, 4); // Set I2C Address and display size
- // Which zones are active. If a zone is active set as true, if a zone is
- // deactived or not needed set to false. Zones are then placed in an array.
- bool zoneActive[] = {true,true,true,true};
- bool zoneManual[] = {false,false,false,false};
- bool zoneAuto[] = {true,true,true,true};
- bool zoneAutoTimer[] = {false,false,false,false};
- bool zonePump[] = {false,false,false,false};
- bool zoneManualPump[] = {false,false,false,false};
- // Counters and bools for progressing through each Zone and Manipulating the LCD menu
- int zoneNumber = 0; // Which zone the loop is controlling
- int menuZone = 0; // Which Zone the menu is viewing/adjusting
- int lastMenuZone = 0;
- // Sensor trigger points to trigger each zones output on/off.
- // NOTE: GIKFUN 1.2 Moisture sensors seem to range from ~340(Capacitor submerged
- // in water) to ~670(Dry air)
- // GIKFUN 2.0 Seem to run this range (~290 wet, ~700 Dry) but responds
- // much slower as moisture increases, responds quickly to drying). These
- // tests done with factory ~8" jumper harness. Will retest with final
- // length harnesses and adjust MiniTaco V1.0 Soil Sensors seem to run from
- // ~700 - ~930. - 8" Harness, retest with 7.5' Harness MiniTaco V1.5 Soil
- // Sensors seem to run from ~490 - ~890. - 8" Harness, retest with 7.5'
- // Harness
- int triggerHigh[] = {550, 550, 550, 550};
- int triggerLow[] = {670, 670, 670, 670};
- // ---Pin Assignments--
- // Set Pin Assignments for User Input Buttons
- const int button1 = 10;
- const int button2 = 11;
- const int button3 = 12;
- const int button4 = 13;
- // Set Pin Assignments for Zone Status LED's
- const int zoneLED[] = {6, 7, 8, 9}; // Zone 1-4 pins for LEDs
- // Set pin assignments for OUT pins
- const int output[] = {2, 3, 4, 5}; // Zone 1-4 pins for outputs to relays
- const int sensPin[] = {A0, A1, A2, A3}; // Zone 1-4 Analog ADC pins
- // --Variables--
- // Menu Related Variables
- bool menuOn = true; // state of the display menu
- int optionSelect = 0; // which menu option is selected
- int lastOptionSelect = 0;
- int lastItemSelect = 0;
- int itemSelect = 0;
- int buttonState1 = 0; // current state of each button
- int buttonState2 = 0;
- int buttonState3 = 0;
- int buttonState4 = 0;
- int lastButtonState1 = 0; // previous state of each button
- int lastButtonState2 = 0;
- int lastButtonState3 = 0;
- int lastButtonState4 = 0;
- unsigned long displayTimer = 10000; // timer to automatically turn off the display
- unsigned long lastDisplayTimer = 0;
- // Delay Variables
- const int manualDayTimer[] = {86400000, 86400000, 86400000, 86400000}; // delay for once a day manual watering mode
- unsigned long lastManualDayTimer[] = {0, 0, 0, 0,};
- const int sensorReadDelay[] = {600000, 600000, 600000, 600000}; // delay between sensor readings in millis
- unsigned long lastSensorReadTime[] = {0, 0, 0, 0}; // the last time a sensor was read
- // Pump timers to monitor zone "on" time of each output. 60000 = 1 minutes
- unsigned long pumpTimer[] = {60000, 60000, 60000, 60000}; //Pump timers in array
- // Last value of the Pump timers
- unsigned long lastPumpTimer[] = {0, 0, 0, 0}; // last value of Pump timers in array
- // Analog sensor reading values sensors 1-4
- int sensor[] = {0, 0, 0, 0}; // Sensor reading values array
- // EEPROM addresses
- const int zone1TrigLowAddress = 0;
- const int zone2TrigLowAddress = 1;
- const int zone3TrigLowAddress = 2;
- const int zone4TrigLowAddress = 3;
- const int zone1TrigHighAddress = 4;
- const int zone2TrigHighAddress = 5;
- const int zone3TrigHighAddress = 6;
- const int zone4TrigHighAddress = 7;
- const int zone1OnAddress = 8;
- const int zone2OnAddress = 9;
- const int zone3OnAddress = 10;
- const int zone4OnAddress = 11;
- const int firstBootAddress = 12; // Address to tell the memory if this is the first time this chip has run.
- int firstBootCount;
- void setup() {
- // firstBootCount = EEPROM.read(firstBootAddress);
- // if (firstBootCount == 90) {
- // triggerLow[0] = EEPROM.read(zone1TrigLowAddress);
- // triggerLow[1] = EEPROM.read(zone2TrigLowAddress);
- // triggerLow[2] = EEPROM.read(zone3TrigLowAddress);
- // triggerLow[3] = EEPROM.read(zone4TrigLowAddress);
- // triggerHigh[0] = EEPROM.read(zone1TrigHighAddress);
- // triggerHigh[1] = EEPROM.read(zone2TrigHighAddress);
- // triggerHigh[2] = EEPROM.read(zone3TrigHighAddress);
- // triggerHigh[3] = EEPROM.read(zone4TrigHighAddress);
- // zoneActive[0] = EEPROM.read(zone1OnAddress);
- // zoneActive[1] = EEPROM.read(zone2OnAddress);
- // zoneActive[2] = EEPROM.read(zone3OnAddress);
- // zoneActive[3] = EEPROM.read(zone4OnAddress);
- // }
- // else if (firstBootCount != 90) {
- // EEPROM.write(zone1TrigLowAddress, 800);
- // EEPROM.write(zone2TrigLowAddress, 800);
- // EEPROM.write(zone3TrigLowAddress, 800);
- // EEPROM.write(zone4TrigLowAddress, 800);
- // EEPROM.write(zone1TrigHighAddress, 550);
- // EEPROM.write(zone2TrigHighAddress, 550);
- // EEPROM.write(zone3TrigHighAddress, 550);
- // EEPROM.write(zone4TrigHighAddress, 550);
- // EEPROM.write(zone1OnAddress, true);
- // EEPROM.write(zone2OnAddress, false);
- // EEPROM.write(zone3OnAddress, false);
- // EEPROM.write(zone4OnAddress, false);
- // EEPROM.write(firstBootAddress, 90);
- // }
- // triggerLow[0] = EEPROM.read(zone1TrigLowAddress);
- // triggerLow[1] = EEPROM.read(zone2TrigLowAddress);
- // triggerLow[2] = EEPROM.read(zone3TrigLowAddress);
- // triggerLow[3] = EEPROM.read(zone4TrigLowAddress);
- // triggerHigh[0] = EEPROM.read(zone1TrigHighAddress);
- // triggerHigh[1] = EEPROM.read(zone2TrigHighAddress);
- // triggerHigh[2] = EEPROM.read(zone3TrigHighAddress);
- // triggerHigh[3] = EEPROM.read(zone4TrigHighAddress);
- // zoneActive[0] = EEPROM.read(zone1OnAddress);
- // zoneActive[1] = EEPROM.read(zone2OnAddress);
- // zoneActive[2] = EEPROM.read(zone3OnAddress);
- // zoneActive[3] = EEPROM.read(zone4OnAddress);
- lcd.begin();
- lcd.clear();
- lcd.home();
- lcd.print(" --DOROTHY--");
- lcd.setCursor(0, 1);
- lcd.print(" Irrigation");
- lcd.setCursor(0, 2);
- lcd.print(" System 2.0");
- lcd.setCursor(0, 3);
- lcd.print(" LOADING...");
- delay(2000);
- lcd.clear();
- // set LED indicator pins to output.
- pinMode(zoneLED[0], OUTPUT);
- pinMode(zoneLED[1], OUTPUT);
- pinMode(zoneLED[2], OUTPUT);
- pinMode(zoneLED[3], OUTPUT);
- // set OUT pins to output
- pinMode(output[0], OUTPUT);
- pinMode(output[1], OUTPUT);
- pinMode(output[2], OUTPUT);
- pinMode(output[3], OUTPUT);
- // set Sensor pins to input
- pinMode(sensPin[0], INPUT);
- pinMode(sensPin[1], INPUT);
- pinMode(sensPin[2], INPUT);
- pinMode(sensPin[3], INPUT);
- // set Button pins to input
- pinMode(button1, INPUT);
- pinMode(button2, INPUT);
- pinMode(button3, INPUT);
- pinMode(button4, INPUT);
- }
- void displayMenu() {
- if (menuOn) { // if the display is supposed to be on
- lcd.display(); // turn the display on
- lcd.backlight();
- switch (optionSelect) {
- case 0:
- lcd.home();
- lcd.print(" -ZONE ");
- lcd.print(menuZone+1);
- lcd.print(" ");
- if (zoneActive[menuZone] && !zonePump[menuZone]) {
- lcd.print("ACTIVE");
- lcd.print("-");
- lcd.setCursor(0, 1);
- lcd.print("< >");
- lcd.setCursor(0, 2);
- lcd.print(" Press DOWN To See/");
- lcd.setCursor(0, 3);
- lcd.print(" Set Details");
- }
- else if (!zoneActive[menuZone] && !zonePump[menuZone] && !zoneManualPump[menuZone]) {
- lcd.print("DISABLED");
- lcd.print("-");
- lcd.setCursor(0, 1);
- lcd.print("< >");
- lcd.setCursor(0, 2);
- lcd.print(" Press DOWN To See/");
- lcd.setCursor(0, 3);
- lcd.print(" Set Details");
- }
- else if (zonePump[menuZone] || zoneManualPump[menuZone]) {
- lcd.print("PUMPING");
- lcd.print("-");
- lcd.setCursor(0, 1);
- lcd.print("< >");
- lcd.setCursor(0, 2);
- lcd.print(" Press DOWN To See/");
- lcd.setCursor(0, 3);
- lcd.print(" Set Details");
- }
- break;
- case 1:
- lcd.home();
- lcd.print(" -ZONE ");
- lcd.print(menuZone+1);
- lcd.print(" SETTING-");
- lcd.setCursor(0, 1);
- lcd.print(" Moisture Level: ");
- lcd.print(sensor[menuZone]);
- lcd.setCursor(0, 2);
- lcd.print(" DRY SOIL SETTING");
- lcd.setCursor(0,3);
- lcd.print("<");
- lcd.setCursor(8, 3);
- lcd.print(triggerLow[menuZone]);
- lcd.setCursor(19,3);
- lcd.print(">");
- break;
- case 2:
- lcd.home();
- lcd.print(" -ZONE ");
- lcd.print(menuZone+1);
- lcd.print(" SETTING-");
- lcd.setCursor(0, 1);
- lcd.print(" Pump Timer: ");
- lcd.setCursor(0, 2);
- lcd.print("< ");
- lcd.print(pumpTimer[menuZone] / 60000);
- lcd.print(" >");
- lcd.setCursor(0,3);
- lcd.print(" Minutes");
- break;
- case 3:
- lcd.home();
- lcd.print(" -ZONE ");
- lcd.print(menuZone+1);
- lcd.print(" SETTING-");
- lcd.setCursor(0, 1);
- lcd.print(" ZONE: ");
- if (zoneAuto[menuZone] && !zonePump[menuZone] && !zoneManualPump[menuZone]) {
- lcd.print("AUTOMATIC");
- lcd.setCursor(0, 2);
- lcd.print(" PRESS < OR > TO:");
- lcd.setCursor(3, 3);
- lcd.print("GO TO MANUAL MODE");
- }
- else if (zoneManual[menuZone] && !zoneManualPump[menuZone] && !zonePump[menuZone]) {
- lcd.print("MANUAL");
- lcd.setCursor(0, 2);
- lcd.print(" PRESS < OR > TO:");
- lcd.setCursor(3, 3);
- lcd.print("GO TO AUTO MODE");
- }
- else if (zoneManualPump[menuZone]) {
- lcd.print("PUMPING");
- lcd.setCursor(0, 2);
- lcd.print(" PRESS < OR > TO:");
- lcd.setCursor(3, 3);
- lcd.print("GO TO AUTO MODE");
- }
- else if (zonePump[menuZone]) {
- lcd.print("PUMPING");
- lcd.setCursor(0, 2);
- lcd.print(" PRESS < OR > TO:");
- lcd.setCursor(3, 3);
- lcd.print("GO TO MANUAL MODE");
- }
- break;
- case 4:
- lcd.home();
- lcd.print(" -ZONE ");
- lcd.print(menuZone+1);
- lcd.print(" SETTING-");
- lcd.setCursor(0, 1);
- lcd.print(" ZONE: ");
- if (zoneActive[menuZone] && !zonePump[menuZone]) {
- lcd.print("ACTIVE");
- lcd.setCursor(0, 2);
- lcd.print(" PRESS DOWN TO:");
- lcd.setCursor(4, 3);
- lcd.print("DISABLE");
- }
- else if (!zoneActive[menuZone] && !zonePump[menuZone] && !zoneManualPump[menuZone]) {
- lcd.print("DISABLED");
- lcd.setCursor(0, 2);
- lcd.print(" PRESS DOWN TO:");
- lcd.setCursor(4, 3);
- lcd.print("ACTIVATE");
- }
- else if (zonePump[menuZone] || zoneManualPump[menuZone]) {
- lcd.print("PUMPING");
- lcd.setCursor(0, 2);
- lcd.print(" PRESS DOWN TO:");
- lcd.setCursor(4, 3);
- lcd.print("DISABLE");
- }
- break;
- }
- if ((unsigned long)(millis() - lastDisplayTimer) >= displayTimer) {
- menuOn = false;
- }
- } else if (!menuOn) { // if the display is supposed to be off
- lcd.noDisplay(); // turn the display off
- lcd.noBacklight();
- optionSelect = 0; // back to front screen
- itemSelect = 0;
- menuZone = 0;
- }
- if ((buttonState1 == 0) && (!menuOn)) {
- menuOn = true;
- lastDisplayTimer = millis();
- // optionSelect = 0; // back to front screen
- // menuZone = 0;
- // itemSelect = 0;
- lastButtonState1 = buttonState1;
- }
- }
- void readButtons() {
- buttonState1 = (digitalRead(button1));
- buttonState2 = (digitalRead(button2));
- buttonState3 = (digitalRead(button3));
- buttonState4 = (digitalRead(button4));
- if (buttonState1 != lastButtonState1) {
- if (buttonState1 == LOW) { // if the DOWN button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if (optionSelect < 4) { // if we are in the settings change and not passed the last screen.
- optionSelect++;
- }
- else if (optionSelect = 4) {
- if (zoneActive[menuZone]) {
- zonePump[menuZone] = false;
- zoneManualPump[menuZone] = false;
- zoneActive[menuZone] = false;
- digitalWrite(output[menuZone], LOW);
- digitalWrite(zoneLED[menuZone], LOW); // Turn Zone Indicator LED Off
- }
- else if (zonePump[menuZone]) {
- zonePump[menuZone] = false;
- zoneManualPump[menuZone] = false;
- zoneActive[menuZone] = false;
- digitalWrite(output[menuZone], LOW);
- digitalWrite(zoneLED[menuZone], LOW); // Turn Zone Indicator LED Off
- }
- else if (zoneManualPump[menuZone]) {
- zonePump[menuZone] = false;
- zoneManualPump[menuZone] = false;
- zoneActive[menuZone] = false;
- digitalWrite(output[menuZone], LOW);
- digitalWrite(zoneLED[menuZone], LOW); // Turn Zone Indicator LED Off
- }
- else if (!zoneActive[menuZone]) {
- zonePump[menuZone] = false;
- zoneManualPump[menuZone] = false;
- zoneActive[menuZone] = true;
- lastPumpTimer[menuZone] = millis();
- lastManualDayTimer[menuZone] = millis();
- digitalWrite(zoneLED[menuZone], HIGH);
- }
- optionSelect = 0;
- }
- }
- lastButtonState1 = buttonState1;
- }
- if (buttonState4 != lastButtonState4) {
- if (buttonState4 == LOW) { // if the UP button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if ((optionSelect != 0) && (optionSelect != 0)) { // if we are not in the settings change and not passed the first screen.
- optionSelect--;
- }
- }
- lastButtonState4 = buttonState4;
- }
- if (optionSelect == 0) { // if we are not adjusting settings
- if (buttonState2 != lastButtonState2) { // if the right button has been pressed
- if (buttonState2 == LOW) { // if the right button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if ((menuZone <= 3) && (menuZone != 3)) { // if we are not past the last menu screen
- menuZone++;
- }
- else if (menuZone == 3) { // if we are at the last menu screen
- menuZone = 0;
- }
- }
- lastButtonState2 = buttonState2;
- }
- if (buttonState3 != lastButtonState3) { // if the left button has been pressed
- if (buttonState3 == LOW) { // if the left button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if (menuZone > 0) { // if we are not at the first menu screen
- menuZone--;
- }
- else if (menuZone == 0) {
- menuZone = 3;
- }
- }
- lastButtonState3 = buttonState3;
- }
- }
- else if (optionSelect == 1) { // if we are adjusting settings
- buttonState2 = (digitalRead(button2));
- buttonState3 = (digitalRead(button3));
- if (buttonState2 != lastButtonState2) { // if the right button has been pressed
- if (buttonState2 == LOW) { // if the right button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if (triggerLow[menuZone] < 700) {
- triggerLow[menuZone] = (triggerLow[menuZone] + 10);
- }
- else if (triggerLow[menuZone] >= 700) {
- triggerLow[menuZone] = 700;
- }
- }
- lastButtonState2 = buttonState2;
- }
- if (buttonState3 != lastButtonState3) { // if the left button has been pressed
- if (buttonState3 == LOW) { // if the left button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if (triggerLow[menuZone] > 600) {
- triggerLow[menuZone] = (triggerLow[menuZone] - 10);
- }
- else if (triggerLow[menuZone] <= 600) {
- triggerLow[menuZone] = 600;
- }
- }
- lastButtonState3 = buttonState3;
- }
- }
- else if (optionSelect == 2) { // if we are adjusting settings
- buttonState2 = (digitalRead(button2));
- buttonState3 = (digitalRead(button3));
- if (buttonState2 != lastButtonState2) { // if the right button has been pressed
- if (buttonState2 == LOW) { // if the right button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if (pumpTimer[menuZone] < 600000) {
- pumpTimer[menuZone] = (pumpTimer[menuZone] + 60000);
- }
- else if (pumpTimer[menuZone] >= 600000) {
- pumpTimer[menuZone] = 600000;
- }
- }
- lastButtonState2 = buttonState2;
- }
- if (buttonState3 != lastButtonState3) { // if the left button has been pressed
- if (buttonState3 == LOW) { // if the left button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if (pumpTimer[menuZone] > 60000) {
- pumpTimer[menuZone] = (pumpTimer[menuZone] - 60000);
- }
- else if (pumpTimer[menuZone] <= 60000) {
- pumpTimer[menuZone] = 60000;
- }
- }
- lastButtonState3 = buttonState3;
- }
- }
- else if (optionSelect == 3) { // if we are adjusting settings
- buttonState2 = (digitalRead(button2));
- buttonState3 = (digitalRead(button3));
- if (buttonState2 != lastButtonState2 || buttonState3 != lastButtonState3) { // if the right button has been pressed
- if (buttonState2 == LOW || buttonState3 == LOW) { // if either button has been pressed
- lcd.clear();
- lastDisplayTimer = millis();
- if (zoneAuto[menuZone] && !zonePump[menuZone] && !zoneManualPump[menuZone]) {
- zoneAuto[menuZone] = false;
- lastManualDayTimer[menuZone] = millis();
- zoneManual[menuZone] = true;
- }
- else if (zoneManual[menuZone] && !zoneManualPump[menuZone] && !zonePump[menuZone]) {
- zoneManual[menuZone] = false;
- zoneAuto[menuZone] = true;
- }
- else if (zoneManualPump[menuZone]) {
- zoneManualPump[menuZone] = false;
- zonePump[menuZone] = true;
- lastManualDayTimer[menuZone] = millis();
- zoneManual[menuZone] = false;
- zoneAuto[menuZone] = true;
- }
- else if (zonePump[menuZone]) {
- lastManualDayTimer[menuZone] = millis();
- zonePump[menuZone] = false;
- zoneManualPump[menuZone] = true;
- zoneAuto[menuZone] = false;
- lastManualDayTimer[menuZone] = millis();
- zoneManual[menuZone] = true;
- }
- }
- lastButtonState2 = buttonState2;
- lastButtonState3 = buttonState3;
- }
- }
- }
- void settingSave() {
- EEPROM.update(zone1OnAddress, zoneActive[0]);
- EEPROM.update(zone2OnAddress, zoneActive[1]);
- EEPROM.update(zone3OnAddress, zoneActive[2]);
- EEPROM.update(zone4OnAddress, zoneActive[3]);
- EEPROM.update(zone1TrigLowAddress, triggerLow[0]);
- EEPROM.update(zone2TrigLowAddress, triggerLow[1]);
- EEPROM.update(zone3TrigLowAddress, triggerLow[2]);
- EEPROM.update(zone4TrigLowAddress, triggerLow[3]);
- EEPROM.update(zone1TrigHighAddress, triggerHigh[0]);
- EEPROM.update(zone2TrigHighAddress, triggerHigh[1]);
- EEPROM.update(zone3TrigHighAddress, triggerHigh[2]);
- EEPROM.update(zone4TrigHighAddress, triggerHigh[3]);
- }
- void zoneControl() {
- if (zoneAuto[zoneNumber]) {
- if (zoneActive[zoneNumber] && (!zonePump[zoneNumber] && !zoneManualPump[zoneNumber])) {
- sensor[zoneNumber] = analogRead(sensPin[zoneNumber]);
- digitalWrite(zoneLED[zoneNumber], HIGH); // Turn Zone Indicator LED On
- digitalWrite(output[zoneNumber], LOW);
- if ((unsigned long)(millis() - lastSensorReadTime[zoneNumber]) >= sensorReadDelay[zoneNumber]) {
- lastSensorReadTime[zoneNumber] = millis();
- // Set the sensor reading levels for the output trigger for sensor
- if (sensor[zoneNumber] >= triggerLow[zoneNumber]) {
- zonePump[zoneNumber] = true;
- digitalWrite(output[zoneNumber], HIGH);
- lastPumpTimer[zoneNumber] = millis();
- zoneActive[zoneNumber] = false;
- }
- }
- }
- }
- }
- void zoneControlManual() {
- if (zoneManual[zoneNumber]) {
- if (zoneActive[zoneNumber] && (!zonePump[zoneNumber] && !zoneManualPump[zoneNumber])) {
- digitalWrite(zoneLED[zoneNumber], HIGH); // Turn Zone Indicator LED On
- digitalWrite(output[zoneNumber], LOW);
- sensor[zoneNumber] = 0;
- if ((unsigned long)(millis() - lastManualDayTimer[zoneNumber]) > manualDayTimer[zoneNumber]) {
- zoneManualPump[zoneNumber] = true;
- digitalWrite(output[zoneNumber], HIGH);
- lastPumpTimer[zoneNumber] = millis();
- lastManualDayTimer[zoneNumber] = millis();
- zoneActive[zoneNumber] = false;
- }
- }
- }
- }
- // Loop to progress zoneControl and fault monitor through each zone
- void zoneLoop() {
- for (zoneNumber = 0; zoneNumber < 3; zoneNumber++) {
- zoneControl();
- zoneControlManual();
- zoneControlPump();
- }
- for (zoneNumber = 3; zoneNumber > 0; zoneNumber = 0) {
- zoneControl();
- zoneControlManual();
- zoneControlPump();
- }
- }
- void zoneControlPump() {
- if (zonePump[zoneNumber]) {
- if ((unsigned long)(millis() - lastPumpTimer[zoneNumber]) >= pumpTimer[zoneNumber]) {
- if (zoneAutoTimer[zoneNumber]) {
- sensor[zoneNumber] = analogRead(sensPin[zoneNumber]);
- if (sensor[zoneNumber] >= (triggerLow[zoneNumber] - 10)) {
- if (pumpTimer[zoneNumber] <= 360000) {
- pumpTimer[zoneNumber] = pumpTimer[zoneNumber] + 60000;
- }
- else if (pumpTimer[zoneNumber] >= 360000) {
- pumpTimer[zoneNumber] = 360000;
- }
- }
- else if (sensor[zoneNumber] <= (triggerLow[zoneNumber] + 10)) {
- if (pumpTimer[zoneNumber] > 60000) {
- pumpTimer[zoneNumber] = pumpTimer[zoneNumber] - 60000;
- }
- else if (pumpTimer[zoneNumber] <= 60000) {
- pumpTimer[zoneNumber] = 60000;
- }
- }
- }
- digitalWrite(output[zoneNumber], LOW);
- zoneActive[zoneNumber] = true;
- lastSensorReadTime[zoneNumber] = millis();
- zonePump[zoneNumber] = false;
- zoneManualPump[zoneNumber] = false;
- lastManualDayTimer[zoneNumber] = millis();
- }
- }
- else if (zoneManualPump[zoneNumber]) {
- if ((unsigned long)(millis() - lastPumpTimer[zoneNumber]) >= pumpTimer[zoneNumber]) {
- digitalWrite(output[zoneNumber], LOW);
- zoneActive[zoneNumber] = true;
- zonePump[zoneNumber] = false;
- zoneManualPump[zoneNumber] = false;
- lastManualDayTimer[zoneNumber] = millis();
- }
- }
- else if (!zoneManualPump[zoneNumber] && !zonePump[zoneNumber]) {
- digitalWrite(output[zoneNumber], LOW);
- }
- }
- void loop() {
- readButtons();
- zoneLoop();
- displayMenu();
- // settingSave();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement