Advertisement
hms11

4ZoneCommandRev2

Aug 6th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.18 KB | None | 0 0
  1. // ------------------------- ZONE COMMAND HV TACO ---------------------
  2. // ---------------------4 ZONE CONTROL BOARD-------------------
  3. // ------------------------I2C LCD DISPLAY---------------------
  4. // --------------------4 USER INPUT BUTTONS--------------------
  5. // -------------------DESIGNED AND PROGRAMMED BY:--------------
  6. // --------------------------COREY EARL-------------------------
  7. // ----------------REVISION 3 (AUG 5th, 2021)----------------
  8. // ----------------All Zones Appear to Function----------------
  9. // ---------------------More Testing Needed--------------------
  10. //----------------Ready for on-site BETA testing---------------
  11.  
  12. //----------------------------FEATURES:-----------------------------
  13. //-----------------Easy to deactivate/activate each zone------------
  14. //---------------------Watchdog timers for each zone ---------------
  15. //----------------Easy trigger point setting per zone---------------
  16. //--Triggering of wagtchdog attempts to fail individual zones safe--
  17. //---------Per zone fault indication when watchdog triggered--------
  18.  
  19. //--------------------------ISSUES:---------------------------------
  20. //-------EEPROM not working right, more testing needed--------
  21.  
  22. //--------------------------------------------------------
  23.  
  24. // Libraries
  25. #include <EEPROM.h>
  26. #include <LiquidCrystal_I2C.h>
  27. #include <Wire.h>
  28. LiquidCrystal_I2C lcd(0x27, 20, 4); // Set I2C Address and display size
  29.  
  30. // Which zones are active. If a zone is active set as true, if a zone is
  31. // deactived or not needed set to false. Zones are then placed in an array.
  32.  
  33. bool zoneActive[] = {true,true,true,true};
  34.  
  35. // Counter for progressing through each Zone
  36.  
  37. int zoneNumber = 0; // Which zone the loop is controlling
  38.  
  39. // If the zone is in a fault state;
  40.  
  41. bool faultFlash[] = {false,false,false,false};
  42.  
  43. // Sensor trigger points to trigger each zones output on/off.
  44.  
  45. // NOTE: GIKFUN 1.2 Moisture sensors seem to range from ~340(Capacitor submerged
  46. // in water) to ~670(Dry air)
  47. // GIKFUN 2.0 Seem to run this range (~290 wet, ~700 Dry) but responds
  48. // much slower as moisture increases, responds quickly to drying). These
  49. // tests done with factory ~8" jumper harness. Will retest with final
  50. // length harnesses and adjust MiniTaco V1.0 Soil Sensors seem to run from
  51. // ~700 - ~930. - 8" Harness, retest with 7.5' Harness MiniTaco V1.5 Soil
  52. // Sensors seem to run from ~490 - ~890. - 8" Harness, retest with 7.5'
  53. // Harness
  54.  
  55. int triggerHigh[] = {550, 550, 550, 550};
  56. int triggerLow[] = {800, 800, 800, 800};
  57.  
  58. // ---Pin Assignments--
  59.  
  60. // Set Pin Assignments for User Input Buttons
  61.  
  62. const int button1 = 10;
  63. const int button2 = 11;
  64. const int button3 = 12;
  65. const int button4 = 13;
  66.  
  67. // Set Pin Assignments for Zone Status LED's
  68.  
  69. const int zoneLED[] = {6, 7, 8, 9}; // Zone 1-4 pins for LEDs
  70.  
  71. // Set pin assignments for OUT pins
  72.  
  73. const int output[] = {2, 3, 4, 5}; // Zone 1-4 pins for outputs to relays
  74.  
  75. const int sensPin[] = {A0, A1, A2, A3}; // Zone 1-4 Analog ADC pins
  76.  
  77. // --Variables--
  78.  
  79. // Menu Related Variables
  80. bool menuOn = true; // state of the display menu
  81. int menu[5]; // number of menu items
  82. int optionSelect = 0; // which menu option is selected
  83. int lastOptionSelect = 0;
  84. int lastItemSelect = 0;
  85. int itemSelect = 0;
  86. int buttonState1 = 0; // current state of each button
  87. int buttonState2 = 0;
  88. int buttonState3 = 0;
  89. int buttonState4 = 0;
  90. int lastButtonState1 = 0; // previous state of each button
  91. int lastButtonState2 = 0;
  92. int lastButtonState3 = 0;
  93. int lastButtonState4 = 0;
  94. unsigned long displayTimer = 10000; // timer to automatically turn off the display
  95. unsigned long lastDisplayTimer = 0;
  96.  
  97. // Delay Variables
  98.  
  99. const int sensorReadDelay[] = {500, 500, 500, 500}; // delay between sensor readings in millis
  100. unsigned long lastSensorReadTime[] = {0, 0, 0, 0}; // the last time a sensor was read
  101.  
  102. // Watchdog timers to monitor zone "on" time of each output. 600000 = 10 minutes
  103.  
  104. unsigned long watchDog[] = {600000, 600000, 600000, 600000}; // Watchdog timers in array
  105.  
  106. // Last value of the Watchdog timers
  107.  
  108. unsigned long lastWatchDog[] = {0, 0, 0, 0}; // last value of Watchdog timers in array
  109.  
  110. // Fault LED flash timers
  111.  
  112. const int flashLED[] = {500, 500, 500, 500}; // write flash timers to array
  113.  
  114. unsigned long lastFlashLED[] = {0, 0, 0, 0}; // write last flash times to array
  115.  
  116. // Analog sensor reading values sensors 1-4
  117.  
  118. int sensor[] = {0, 0, 0, 0}; // Sensor reading values array
  119.  
  120. // Sensor pins 1-4 states ("1" = Low, "2" = Neutral, "3" = High)
  121.  
  122. int zoneState[] = {0, 0, 0, 0}; // Zone pin state array
  123.  
  124. // Output pin values outputs 1-4
  125.  
  126. int outRead[] = {0, 0, 0, 0}; // Output pin value array
  127.  
  128. // Output LED pin values outputs 1-4
  129.  
  130. int ledState[] = {0, 0, 0, 0}; // Zone Active LED high/low array
  131.  
  132. // EEPROM addresses
  133. const int zone1TrigAddress = 0;
  134. const int zone2TrigAddress = 1;
  135. const int zone3TrigAddress = 2;
  136. const int zone4TrigAddress = 3;
  137. const int firstRun = 4; // Address to tell the memory if this is the first time this chip has run.
  138. int startUp;
  139.  
  140.  
  141. void setup() {
  142. // put your setup code here, to run once:
  143. lcd.begin();
  144. lcd.clear();
  145. lcd.home();
  146. lcd.print(" --ZONE COMMAND--");
  147. lcd.setCursor(0, 1);
  148. lcd.print(" Irrigation");
  149. lcd.setCursor(0, 2);
  150. lcd.print(" System");
  151. lcd.setCursor(0, 3);
  152. lcd.print(" LOADING...");
  153. delay(2000);
  154. lcd.clear();
  155. // set LED indicator pins to output.
  156. pinMode(zoneLED[0], OUTPUT);
  157. pinMode(zoneLED[1], OUTPUT);
  158. pinMode(zoneLED[2], OUTPUT);
  159. pinMode(zoneLED[3], OUTPUT);
  160. // set OUT pins to output
  161. pinMode(output[0], OUTPUT);
  162. pinMode(output[1], OUTPUT);
  163. pinMode(output[2], OUTPUT);
  164. pinMode(output[3], OUTPUT);
  165. // set Sensor pins to input
  166. pinMode(sensPin[0], INPUT);
  167. pinMode(sensPin[1], INPUT);
  168. pinMode(sensPin[2], INPUT);
  169. pinMode(sensPin[3], INPUT);
  170. // set Button pins to input
  171. pinMode(button1, INPUT);
  172. pinMode(button2, INPUT);
  173. pinMode(button3, INPUT);
  174. pinMode(button4, INPUT);
  175.  
  176. }
  177.  
  178.  
  179. void zoneControl() {
  180. if (zoneActive[zoneNumber]) {
  181. sensor[zoneNumber] = analogRead(sensPin[zoneNumber]);
  182. digitalWrite(zoneLED[zoneNumber], HIGH); // Turn Zone Indicator LED On
  183. if ((unsigned long)(millis() - lastWatchDog[zoneNumber]) >= watchDog[zoneNumber]) { // If the watchdog timer has been triggered
  184. zoneActive[zoneNumber] = false; // turn off the zone
  185. faultFlash[zoneNumber] = true; // turn on the fault light
  186. digitalWrite(zoneLED[zoneNumber], LOW); // Turn Zone Indicator LED Off
  187. }
  188. else if ((unsigned long)(millis() - lastSensorReadTime[zoneNumber]) >= sensorReadDelay[zoneNumber]) {
  189. lastSensorReadTime[zoneNumber] = millis();
  190.  
  191. // Set the sensor reading levels for the output trigger for sensor
  192. if (sensor[zoneNumber] >= triggerLow[zoneNumber]) {
  193. zoneState[zoneNumber] = 1; // Reading is above trigger, turn on relay
  194. digitalWrite(output[zoneNumber], HIGH);
  195. }
  196. else if (sensor[zoneNumber] >= triggerLow[zoneNumber] && sensor[zoneNumber] <= triggerHigh[zoneNumber]) {
  197. zoneState[zoneNumber] = 2; // Reading is in between triggers, maintain relay state
  198. lastWatchDog[zoneNumber] = millis();
  199. }
  200. else if (sensor[zoneNumber] <= triggerHigh[zoneNumber]) {
  201. zoneState[zoneNumber] = 3; // Reading is below trigger, turn off relay
  202. digitalWrite(output[zoneNumber], LOW);
  203. lastWatchDog[zoneNumber] = millis();
  204. }
  205. }
  206. }
  207. }
  208.  
  209. // Running the Fault Flash
  210.  
  211. void faultFlashLED() {
  212. if (faultFlash[zoneNumber]) { // if the zone is in a fault state
  213. ledState[zoneNumber] = digitalRead(zoneLED[zoneNumber]); // check state of zone indicator LED
  214. if ((unsigned long)(millis() - lastFlashLED[zoneNumber]) >= flashLED[zoneNumber]) {
  215. lastFlashLED[zoneNumber] = millis();
  216. if (ledState[zoneNumber] == HIGH) {
  217. digitalWrite(zoneLED[zoneNumber], LOW);
  218. }
  219. else if (ledState[zoneNumber] == LOW) {
  220. digitalWrite(zoneLED[zoneNumber], HIGH);
  221. }
  222. }
  223. digitalWrite(output[zoneNumber], LOW); // shut the relay off
  224. }
  225. }
  226.  
  227. // Loop to progress zoneControl and fault monitor through each zone
  228.  
  229. void zoneLoop() {
  230. for (zoneNumber = 0; zoneNumber < 3; zoneNumber++) {
  231. zoneControl();
  232. faultFlashLED();
  233. }
  234. for (zoneNumber = 3; zoneNumber > 0; zoneNumber = 0) {
  235. zoneControl();
  236. faultFlashLED();
  237. }
  238. }
  239.  
  240. void readButtons() {
  241. buttonState1 = (digitalRead(button1));
  242. buttonState2 = (digitalRead(button2));
  243. buttonState3 = (digitalRead(button3));
  244. buttonState4 = (digitalRead(button4));
  245. if (buttonState1 != lastButtonState1) {
  246. if (buttonState1 == LOW) { // if the DOWN button has been pressed
  247. lastDisplayTimer = millis();
  248. if ((optionSelect != 0) && (itemSelect != 5)) { // if we are not in the settings change and not passed the last screen.
  249. itemSelect++;
  250. }
  251. else if ((optionSelect != 0) && (itemSelect = 5)) {
  252. itemSelect = 0;
  253. }
  254. }
  255. lastButtonState1 = buttonState1;
  256. }
  257. if (buttonState4 != lastButtonState4) {
  258. if (buttonState4 == LOW) { // if the UP button has been pressed
  259. lastDisplayTimer = millis();
  260. if ((optionSelect != 0) && (itemSelect != 0)) { // if we are not in the settings change and not passed the first screen.
  261. itemSelect--;
  262. }
  263. }
  264. lastButtonState4 = buttonState4;
  265. }
  266.  
  267. if (itemSelect == 0) { // if we are not adjusting settings
  268.  
  269. if (buttonState2 !=
  270. lastButtonState2) { // if the right button has been pressed
  271. if (buttonState2 == LOW) { // if the right button has been pressed
  272. lastDisplayTimer = millis();
  273. if ((optionSelect <= 4) &&
  274. (optionSelect != 4)) { // if we are not past the last menu screen
  275. optionSelect++;
  276. }
  277. else if (optionSelect == 4) { // if we are at the last menu screen
  278. optionSelect = 0;
  279. }
  280. }
  281. lastButtonState2 = buttonState2;
  282. }
  283. if (buttonState3 !=
  284. lastButtonState3) { // if the left button has been pressed
  285. if (buttonState3 == LOW) { // if the left button has been pressed
  286. lastDisplayTimer = millis();
  287. if (optionSelect > 0) { // if we are not at the first menu screen
  288. optionSelect--;
  289. }
  290. else if (optionSelect == 0) {
  291. optionSelect = 4;
  292. }
  293. }
  294. lastButtonState3 = buttonState3;
  295. }
  296. }
  297.  
  298. else if (itemSelect == 2) { // if we are adjusting settings
  299. buttonState2 = (digitalRead(button2));
  300. buttonState3 = (digitalRead(button3));
  301.  
  302. if (buttonState2 !=
  303. lastButtonState2) { // if the right button has been pressed
  304. if (buttonState2 == LOW) { // if the right button has been pressed
  305. lastDisplayTimer = millis();
  306. if (optionSelect == 1) { // if we are adjusting Zone 1
  307. triggerLow[0] = (triggerLow[0] + 25);
  308. }
  309. else if (optionSelect == 2) { // if we are adjusting Zone 2
  310. triggerLow[1] = (triggerLow[1] + 25);
  311. }
  312. else if (optionSelect == 3) { // if we are adjusting Zone 3
  313. triggerLow[2] = (triggerLow[2] + 25);
  314. }
  315. else if (optionSelect == 4) { // if we are adjusting Zone 4
  316. triggerLow[3] = (triggerLow[3] + 25);
  317. }
  318. }
  319. lastButtonState2 = buttonState2;
  320. lcd.clear();
  321. }
  322. if (buttonState3 !=
  323. lastButtonState3) { // if the left button has been pressed
  324. if (buttonState3 == LOW) { // if the left button has been pressed
  325. lastDisplayTimer = millis();
  326. if (optionSelect == 1) { // if we are adjusting Zone 1
  327. triggerLow[0] = (triggerLow[0] - 25);
  328. }
  329. else if (optionSelect == 2) { // if we are adjusting Zone 2
  330. triggerLow[1] = (triggerLow[1] - 25);
  331. }
  332. else if (optionSelect == 3) { // if we are adjusting Zone 3
  333. triggerLow[2] = (triggerLow[2] - 25);
  334. }
  335. else if (optionSelect == 4) { // if we are adjusting Zone 4
  336. triggerLow[3] = (triggerLow[3] - 25);
  337. }
  338. }
  339. lastButtonState3 = buttonState3;
  340. lcd.clear();
  341. }
  342. }
  343. else if (itemSelect == 3) { // if we are adjusting settings
  344. buttonState2 = (digitalRead(button2));
  345. buttonState3 = (digitalRead(button3));
  346.  
  347. if (buttonState2 !=
  348. lastButtonState2) { // if the right button has been pressed
  349. if (buttonState2 == LOW) { // if the right button has been pressed
  350. lastDisplayTimer = millis();
  351. if (optionSelect == 1) { // if we are adjusting Zone 1
  352. watchDog[0] = (watchDog[0] + 60000);
  353. }
  354. else if (optionSelect == 2) { // if we are adjusting Zone 2
  355. watchDog[1] = (watchDog[1] + 60000);
  356. }
  357. else if (optionSelect == 3) { // if we are adjusting Zone 3
  358. watchDog[2] = (watchDog[2] + 60000);
  359. }
  360. else if (optionSelect == 4) { // if we are adjusting Zone 4
  361. watchDog[3] = (watchDog[3] + 60000);
  362. }
  363. }
  364. lastButtonState2 = buttonState2;
  365. lcd.clear();
  366. }
  367. if (buttonState3 !=
  368. lastButtonState3) { // if the left button has been pressed
  369. if (buttonState3 == LOW) { // if the left button has been pressed
  370. lastDisplayTimer = millis();
  371. if (optionSelect == 1) { // if we are adjusting Zone 1
  372. watchDog[0] = (watchDog[0] - 60000);
  373. }
  374. else if (optionSelect == 2) { // if we are adjusting Zone 2
  375. watchDog[1] = (watchDog[1] - 60000);
  376. }
  377. else if (optionSelect == 3) { // if we are adjusting Zone 3
  378. watchDog[2] = (watchDog[2] - 60000);
  379. }
  380. else if (optionSelect == 4) { // if we are adjusting Zone 4
  381. watchDog[3] = (watchDog[3] - 60000);
  382. }
  383. }
  384. lastButtonState3 = buttonState3;
  385. lcd.clear();
  386. }
  387. }
  388.  
  389. else if (itemSelect == 5) { // if we are disabling/enabling the zone
  390. buttonState2 = (digitalRead(button1));
  391. buttonState3 = (digitalRead(button3));
  392.  
  393. if (buttonState2 !=
  394. lastButtonState2) { // if the right button has been pressed
  395. if (buttonState2 == LOW) { // if the right button has been pressed
  396. lastDisplayTimer = millis();
  397. if (optionSelect == 1) { // if we are adjusting Zone 1
  398. if (zoneActive[0]) {
  399. zoneActive[0] = false;
  400. itemSelect = 0;
  401. }
  402. else if (!zoneActive[0]) {
  403. zoneActive[0] = true;
  404. faultFlash[0] = false;
  405. itemSelect = 0;
  406. }
  407. }
  408. else if (optionSelect == 2) { // if we are adjusting Zone 2
  409. if (zoneActive[1]) {
  410. zoneActive[1] = false;
  411. itemSelect = 0;
  412. }
  413. else if (!zoneActive[1]) {
  414. zoneActive[1] = true;
  415. faultFlash[1] = false;
  416. itemSelect = 0;
  417. }
  418. }
  419. else if (optionSelect == 3) { // if we are adjusting Zone 3
  420. if (zoneActive[2]) {
  421. zoneActive[2] = false;
  422. itemSelect = 0;
  423. }
  424. else if (!zoneActive[2]) {
  425. zoneActive[2] = true;
  426. faultFlash[2] = false;
  427. itemSelect = 0;
  428. }
  429. }
  430. else if (optionSelect == 4) { // if we are adjusting Zone 4
  431. if (zoneActive[3]) {
  432. zoneActive[3] = false;
  433. itemSelect = 0;
  434. }
  435. else if (!zoneActive[3]) {
  436. zoneActive[3] = true;
  437. faultFlash[3] = false;
  438. itemSelect = 0;
  439. }
  440. }
  441. }
  442. lastButtonState2 = buttonState2;
  443. }
  444. if (buttonState3 !=
  445. lastButtonState3) { // if the left button has been pressed
  446. if (buttonState3 == LOW) { // if the left button has been pressed
  447. lastDisplayTimer = millis();
  448. if (zoneActive[0]) {
  449. zoneActive[0] = false;
  450. itemSelect = 0;
  451. }
  452. else if (!zoneActive[0]) {
  453. zoneActive[0] = true;
  454. faultFlash[0] = false;
  455. itemSelect = 0;
  456. }
  457. }
  458. else if (optionSelect == 2) { // if we are adjusting Zone 2
  459. if (zoneActive[1]) {
  460. zoneActive[1] = false;
  461. itemSelect = 0;
  462. }
  463. else if (!zoneActive[1]) {
  464. zoneActive[1] = true;
  465. faultFlash[1] = false;
  466. itemSelect = 0;
  467. }
  468. }
  469. else if (optionSelect == 3) { // if we are adjusting Zone 3
  470. if (zoneActive[2]) {
  471. zoneActive[2] = false;
  472. itemSelect = 0;
  473. }
  474. else if (!zoneActive[2]) {
  475. zoneActive[2] = true;
  476. faultFlash[2] = false;
  477. itemSelect = 0;
  478. }
  479. }
  480. else if (optionSelect == 4) { // if we are adjusting Zone 4
  481. if (zoneActive[3]) {
  482. zoneActive[3] = false;
  483. itemSelect = 0;
  484. }
  485. else if (!zoneActive[3]) {
  486. zoneActive[3] = true;
  487. faultFlash[3] = false;
  488. itemSelect = 0;
  489. }
  490. }
  491. lastButtonState3 = buttonState3;
  492. }
  493. }
  494. }
  495.  
  496.  
  497. void displayMenu() {
  498. if (menuOn) { // if the display is supposed to be on
  499. lcd.display(); // turn the display on
  500. lcd.backlight();
  501.  
  502. if (optionSelect != lastOptionSelect) {
  503. lcd.clear();
  504. lastOptionSelect = optionSelect;
  505. }
  506.  
  507. else if (itemSelect != lastItemSelect) {
  508. lcd.clear();
  509. lastItemSelect = itemSelect;
  510. }
  511.  
  512. switch (optionSelect) {
  513.  
  514. case 0:
  515. lcd.home();
  516. lcd.print("Zone1: ");
  517. lcd.print(sensor[0]);
  518. if (zoneActive[0]) {
  519. lcd.setCursor(10, 0);
  520. lcd.print(" ACTIVE");
  521. }
  522.  
  523. else if (!zoneActive[0]) {
  524. lcd.setCursor(10, 0);
  525. lcd.print(" OFF");
  526. }
  527. lcd.setCursor(0, 1);
  528. lcd.print("Zone2: ");
  529. lcd.print(sensor[1]);
  530. if (zoneActive[1]) {
  531. lcd.setCursor(10, 1);
  532. lcd.print(" ACTIVE");
  533. }
  534.  
  535. else if (!zoneActive[1]) {
  536. lcd.setCursor(10, 1);
  537. lcd.print(" OFF");
  538. }
  539. lcd.setCursor(0, 2);
  540. lcd.print("Zone3: ");
  541. lcd.print(sensor[2]);
  542. if (zoneActive[2]) {
  543. lcd.setCursor(10, 2);
  544. lcd.print(" ACTIVE");
  545. }
  546.  
  547. else if (!zoneActive[2]) {
  548. lcd.setCursor(10, 2);
  549. lcd.print(" OFF");
  550. }
  551. lcd.setCursor(0, 3);
  552. lcd.print("Zone4: ");
  553. lcd.print(sensor[3]);
  554. if (zoneActive[3]) {
  555. lcd.setCursor(10, 3);
  556. lcd.print(" ACTIVE");
  557. }
  558.  
  559. else if (!zoneActive[3]) {
  560. lcd.setCursor(10, 3);
  561. lcd.print(" OFF");
  562. }
  563. break;
  564.  
  565. case 1:
  566. if (itemSelect == 0 && zoneActive[0] == true) {
  567. lcd.home();
  568. lcd.print(" -ZONE 1 ACTIVE-");
  569. lcd.setCursor(0, 1);
  570. lcd.print("< >");
  571. lcd.setCursor(0, 2);
  572. lcd.print(" Press DOWN To See/");
  573. lcd.setCursor(0, 3);
  574. lcd.print(" Set Details");
  575. }
  576.  
  577. else if (itemSelect == 0 && zoneActive[0] == false) {
  578. lcd.home();
  579. lcd.print(" -ZONE 1 DISABLED-");
  580. lcd.setCursor(0, 1);
  581. lcd.print("< >");
  582. lcd.setCursor(0, 2);
  583. lcd.print(" Press DOWN To See/");
  584. lcd.setCursor(0, 3);
  585. lcd.print(" Set Details");
  586. }
  587.  
  588. else if (itemSelect == 4 && zoneActive[0] == false) {
  589. lcd.home();
  590. lcd.print(" -ZONE 1 SETTING-");
  591. lcd.setCursor(0, 1);
  592. lcd.print(" ZONE: DISABLED");
  593. lcd.setCursor(0, 2);
  594. lcd.print(" PRESS DOWN TO:");
  595. lcd.setCursor(0, 3);
  596. lcd.print(" ACTIVATE ZONE");
  597. }
  598.  
  599. else if (itemSelect == 1) {
  600. lcd.home();
  601. lcd.print(" -ZONE 1 TRIGGER-");
  602. lcd.setCursor(0, 1);
  603. lcd.print(" Moisture Level: ");
  604. lcd.print(sensor[0]);
  605. lcd.setCursor(0, 2);
  606. lcd.print(" Moisture Trigger: ");
  607. lcd.setCursor(8, 3);
  608. lcd.print(triggerLow[0]);
  609. }
  610.  
  611. else if (itemSelect == 2) {
  612. lcd.home();
  613. lcd.print(" -ZONE 1 SETTING-");
  614. lcd.setCursor(0, 1);
  615. lcd.print(" Moisture Level: ");
  616. lcd.print(sensor[0]);
  617. lcd.setCursor(0, 2);
  618. lcd.print(" Moisture Trig Set:");
  619. lcd.setCursor(0, 3);
  620. lcd.print(" < ");
  621. lcd.print(triggerLow[0]);
  622. lcd.print(" >");
  623. }
  624. else if (itemSelect == 3) {
  625. lcd.home();
  626. lcd.print(" -ZONE 1 SETTING-");
  627. lcd.setCursor(0, 1);
  628. lcd.print(" Watchdog Timer:");
  629. lcd.setCursor(0,2);
  630. lcd.print("< ");
  631. lcd.print(watchDog[0] / 60000);
  632. lcd.print(" >");
  633. lcd.setCursor(0,3);
  634. lcd.print(" Minutes");
  635. }
  636. else if (itemSelect == 4 && zoneActive[0] == true) {
  637. lcd.home();
  638. lcd.print(" -ZONE 1 SETTING-");
  639. lcd.setCursor(0, 1);
  640. lcd.print(" ZONE: ACTIVE");
  641. lcd.setCursor(0, 2);
  642. lcd.print(" PRESS DOWN TO");
  643. lcd.setCursor(0, 3);
  644. lcd.print(" DISABLE ZONE");
  645. }
  646. break;
  647.  
  648. case 2:
  649. if (itemSelect == 0 && zoneActive[1] == true) {
  650. lcd.home();
  651. lcd.print(" -ZONE 2 ACTIVE-");
  652. lcd.setCursor(0, 1);
  653. lcd.print("< >");
  654. lcd.setCursor(0, 2);
  655. lcd.print(" Press DOWN To See/");
  656. lcd.setCursor(0, 3);
  657. lcd.print(" Set Details");
  658. }
  659.  
  660. else if (itemSelect == 0 && zoneActive[1] == false) {
  661. lcd.home();
  662. lcd.print(" -ZONE 2 DISABLED-");
  663. lcd.setCursor(0, 1);
  664. lcd.print("< >");
  665. lcd.setCursor(0, 2);
  666. lcd.print(" Press DOWN To See/");
  667. lcd.setCursor(0, 3);
  668. lcd.print(" Set Details");
  669. }
  670.  
  671. else if (itemSelect == 4 && zoneActive[1] == false) {
  672. lcd.home();
  673. lcd.print(" -ZONE 2 SETTING-");
  674. lcd.setCursor(0, 1);
  675. lcd.print(" ZONE: DISABLED");
  676. lcd.setCursor(0, 2);
  677. lcd.print(" PRESS DOWN TO:");
  678. lcd.setCursor(0, 3);
  679. lcd.print(" ACTIVATE ZONE");
  680. }
  681.  
  682. else if (itemSelect == 1) {
  683. lcd.home();
  684. lcd.print(" -ZONE 2 TRIGGER-");
  685. lcd.setCursor(0, 1);
  686. lcd.print(" Moisture Level: ");
  687. lcd.print(sensor[1]);
  688. lcd.setCursor(0, 2);
  689. lcd.print(" Moisture Trigger: ");
  690. lcd.setCursor(8, 3);
  691. lcd.print(triggerLow[1]);
  692. }
  693.  
  694. else if (itemSelect == 2) {
  695. lcd.home();
  696. lcd.print(" -ZONE 2 SETTING-");
  697. lcd.setCursor(0, 1);
  698. lcd.print(" Moisture Level: ");
  699. lcd.print(sensor[1]);
  700. lcd.setCursor(0, 2);
  701. lcd.print(" Moisture Trig Set:");
  702. lcd.setCursor(0, 3);
  703. lcd.print(" < ");
  704. lcd.print(triggerLow[1]);
  705. lcd.print(" >");
  706. }
  707. else if (itemSelect == 3) {
  708. lcd.home();
  709. lcd.print(" -ZONE 2 SETTING-");
  710. lcd.setCursor(0, 1);
  711. lcd.print(" Watchdog Timer:");
  712. lcd.setCursor(0,2);
  713. lcd.print("< ");
  714. lcd.print(watchDog[1] / 60000);
  715. lcd.print(" >");
  716. lcd.setCursor(0,3);
  717. lcd.print(" Minutes");
  718. }
  719.  
  720. else if (itemSelect == 4 && zoneActive[1] == true) {
  721. lcd.home();
  722. lcd.print(" -ZONE 2 SETTING-");
  723. lcd.setCursor(0, 1);
  724. lcd.print(" ZONE: ACTIVE");
  725. lcd.setCursor(0, 2);
  726. lcd.print(" PRESS DOWN TO");
  727. lcd.setCursor(0, 3);
  728. lcd.print(" DISABLE ZONE");
  729. }
  730. break;
  731.  
  732. case 3:
  733. if (itemSelect == 0 && zoneActive[2] == true) {
  734. lcd.home();
  735. lcd.print(" -ZONE 3 ACTIVE-");
  736. lcd.setCursor(0, 1);
  737. lcd.print("< >");
  738. lcd.setCursor(0, 2);
  739. lcd.print(" Press DOWN To See/");
  740. lcd.setCursor(0, 3);
  741. lcd.print(" Set Details");
  742. }
  743.  
  744. else if (itemSelect == 0 && zoneActive[2] == false) {
  745. lcd.home();
  746. lcd.print(" -ZONE 3 DISABLED-");
  747. lcd.setCursor(0, 1);
  748. lcd.print("< >");
  749. lcd.setCursor(0, 2);
  750. lcd.print(" Press DOWN To See/");
  751. lcd.setCursor(0, 3);
  752. lcd.print(" Set Details");
  753. }
  754.  
  755. else if (itemSelect == 4 && zoneActive[2] == false) {
  756. lcd.home();
  757. lcd.print(" -ZONE 3 SETTING-");
  758. lcd.setCursor(0, 1);
  759. lcd.print(" ZONE: DISABLED");
  760. lcd.setCursor(0, 2);
  761. lcd.print(" PRESS DOWN TO:");
  762. lcd.setCursor(0, 3);
  763. lcd.print(" ACTIVATE ZONE");
  764. }
  765.  
  766. else if (itemSelect == 1) {
  767. lcd.home();
  768. lcd.print(" -ZONE 3 TRIGGER-");
  769. lcd.setCursor(0, 1);
  770. lcd.print(" Moisture Level: ");
  771. lcd.print(sensor[2]);
  772. lcd.setCursor(0, 2);
  773. lcd.print(" Moisture Trigger: ");
  774. lcd.setCursor(8, 3);
  775. lcd.print(triggerLow[2]);
  776. }
  777.  
  778. else if (itemSelect == 2) {
  779. lcd.home();
  780. lcd.print(" -ZONE 3 SETTING-");
  781. lcd.setCursor(0, 1);
  782. lcd.print(" Moisture Level: ");
  783. lcd.print(sensor[2]);
  784. lcd.setCursor(0, 2);
  785. lcd.print(" Moisture Trig Set:");
  786. lcd.setCursor(0, 3);
  787. lcd.print(" < ");
  788. lcd.print(triggerLow[2]);
  789. lcd.print(" >");
  790. }
  791. else if (itemSelect == 3) {
  792. lcd.home();
  793. lcd.print(" -ZONE 3 SETTING-");
  794. lcd.setCursor(0, 1);
  795. lcd.print(" Watchdog Timer:");
  796. lcd.setCursor(0,2);
  797. lcd.print("< ");
  798. lcd.print(watchDog[2] / 60000);
  799. lcd.print(" >");
  800. lcd.setCursor(0,3);
  801. lcd.print(" Minutes");
  802. }
  803.  
  804. else if (itemSelect == 4 && zoneActive[2] == true) {
  805. lcd.home();
  806. lcd.print(" -ZONE 3 SETTING-");
  807. lcd.setCursor(0, 1);
  808. lcd.print(" ZONE: ACTIVE");
  809. lcd.setCursor(0, 2);
  810. lcd.print(" PRESS DOWN TO");
  811. lcd.setCursor(0, 3);
  812. lcd.print(" DISABLE ZONE");
  813. }
  814. break;
  815.  
  816. case 4:
  817. if (itemSelect == 0 && zoneActive[3] == true) {
  818. lcd.home();
  819. lcd.print(" -ZONE 4 ACTIVE-");
  820. lcd.setCursor(0, 1);
  821. lcd.print("< >");
  822. lcd.setCursor(0, 2);
  823. lcd.print(" Press DOWN To See/");
  824. lcd.setCursor(0, 3);
  825. lcd.print(" Set Details");
  826. }
  827.  
  828. else if (itemSelect == 0 && zoneActive[3] == false) {
  829. lcd.home();
  830. lcd.print(" -ZONE 4 DISABLED-");
  831. lcd.setCursor(0, 1);
  832. lcd.print("< >");
  833. lcd.setCursor(0, 2);
  834. lcd.print(" Press DOWN To See/");
  835. lcd.setCursor(0, 3);
  836. lcd.print(" Set Details");
  837. }
  838.  
  839. else if (itemSelect == 4 && zoneActive[3] == false) {
  840. lcd.home();
  841. lcd.print(" -ZONE 4 SETTING-");
  842. lcd.setCursor(0, 1);
  843. lcd.print(" ZONE: DISABLED");
  844. lcd.setCursor(0, 2);
  845. lcd.print(" PRESS DOWN TO:");
  846. lcd.setCursor(0, 3);
  847. lcd.print(" ACTIVATE ZONE");
  848. }
  849.  
  850. else if (itemSelect == 1) {
  851. lcd.home();
  852. lcd.print(" -ZONE 4 TRIGGER-");
  853. lcd.setCursor(0, 1);
  854. lcd.print(" Moisture Level: ");
  855. lcd.print(sensor[3]);
  856. lcd.setCursor(0, 2);
  857. lcd.print(" Moisture Trigger: ");
  858. lcd.setCursor(8, 3);
  859. lcd.print(triggerLow[3]);
  860. }
  861.  
  862. else if (itemSelect == 2) {
  863. lcd.home();
  864. lcd.print(" -ZONE 4 SETTING-");
  865. lcd.setCursor(0, 1);
  866. lcd.print(" Moisture Level: ");
  867. lcd.print(sensor[3]);
  868. lcd.setCursor(0, 2);
  869. lcd.print(" Moisture Trig Set:");
  870. lcd.setCursor(0, 3);
  871. lcd.print(" < ");
  872. lcd.print(triggerLow[3]);
  873. lcd.print(" >");
  874. }
  875. else if (itemSelect == 3) {
  876. lcd.home();
  877. lcd.print(" -ZONE 4 SETTING-");
  878. lcd.setCursor(0, 1);
  879. lcd.print(" Watchdog Timer:");
  880. lcd.setCursor(0,2);
  881. lcd.print("< ");
  882. lcd.print(watchDog[3] / 60000);
  883. lcd.print(" >");
  884. lcd.setCursor(0,3);
  885. lcd.print(" Minutes");
  886. }
  887.  
  888. else if (itemSelect == 4 && zoneActive[3] == true) {
  889. lcd.home();
  890. lcd.print(" -ZONE 4 SETTING-");
  891. lcd.setCursor(0, 1);
  892. lcd.print(" ZONE: ACTIVE");
  893. lcd.setCursor(0, 2);
  894. lcd.print(" PRESS DOWN TO");
  895. lcd.setCursor(0, 3);
  896. lcd.print(" DISABLE ZONE");
  897. }
  898. break;
  899. }
  900.  
  901. if ((unsigned long)(millis() - lastDisplayTimer) >= displayTimer) {
  902. menuOn = false;
  903. }
  904. } else if (!menuOn) { // if the display is supposed to be off
  905. lcd.noDisplay(); // turn the display off
  906. lcd.noBacklight();
  907. optionSelect = 0; // back to front screen
  908. itemSelect = 0;
  909. }
  910. if ((buttonState1 == 0) && (!menuOn)) {
  911. menuOn = true;
  912. lastDisplayTimer = millis();
  913. optionSelect = 0; // back to front screen
  914. itemSelect = 0;
  915. lastButtonState1 = buttonState1;
  916. }
  917. }
  918.  
  919.  
  920. void loop() {
  921. // put your main code here, to run repeatedly:
  922. readButtons();
  923. zoneLoop();
  924. displayMenu();
  925. }
  926.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement