Advertisement
hms11

CoopCommand Wifi Rev1.2

Apr 14th, 2021
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.89 KB | None | 0 0
  1.  
  2. // COOP COMMAND WI-FI V1.2 (Full Function Field Test Ready)
  3. // First version of Coop Command, Chicken Coop Control Software.
  4. //
  5. //
  6. // Component/Feature Notes:
  7. // -- Photo Resistor GL5539 W/10K Divider
  8. // -- Interior Temp/Humidity Sensor DHT22
  9. // -- Water Temp Sensor DS18B20
  10. // -- 3 User Input Buttons
  11. // -- I2C Connector for 20x4 LCD Display
  12. // -- User selectable settings
  13. // -- WIFI Connection via ESP32-CAM serial Connection
  14. // -- Settings saved in EEPROM
  15.  
  16.  
  17. // Libraries
  18. #include <EEPROM.h>
  19. #include <DallasTemperature.h>
  20. #include <OneWire.h>
  21. #include <Wire.h>
  22. #include <DHT.h>;
  23. #include <LiquidCrystal_I2C.h>
  24.  
  25. LiquidCrystal_I2C lcd(0x27, 20, 4); // Set I2C Address and display size
  26.  
  27. // pin assignments
  28. const int photocellPin = A0; // analog input pin for photocell
  29. const int button1 = 2; // pin for enter/back button
  30. const int button2 = 3; // pin for user input button 1
  31. const int button3 = 4; // pin for user input button 2
  32. const int bottomSwitchPin = A2; // bottom switch is connected to pin A2
  33. const int topSwitchPin = A1; // top switch is connected to pin A1
  34. const int directionCloseCoopDoorMotorB = 8; // direction close motor b - pin 8
  35. const int directionOpenCoopDoorMotorB = 6; // direction open motor b - pin 9
  36. const int layLightRelay = 10; //output pin controlling lay light relay
  37. const int fanRelay = 11; // output pin controlling ventilation fan relay
  38. const int fanLED = 5; // output pin for ventilation fan LED indicator
  39. const int motorLED = 7; // output pin for ventilation fan LED indicator
  40. const int heatRelay = 9; // output pin controlling water heater relay
  41. const int heatLED = A3; // output pin controlling water heater LED indicator
  42.  
  43. // Data wire is plugged into pin 12
  44. #define ONE_WIRE_BUS 12
  45.  
  46. // Setup a oneWire instance to communicate with any OneWire devices
  47. // (not just Maxim/Dallas temperature ICs)
  48. OneWire oneWire(ONE_WIRE_BUS);
  49.  
  50. // Pass our oneWire reference to Dallas Temperature.
  51. DallasTemperature sensors(&oneWire);
  52.  
  53.  
  54. //DHT Setup
  55. #define DHTPIN 13 // what pin we're connected to
  56. #define DHTTYPE DHT22 // DHT 22 (AM2302)
  57. DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor
  58.  
  59. // Menu Variables and States
  60.  
  61. // Timers
  62. unsigned long ds18b20Delay = 2000; //delay so sensor is read every two seconds
  63. unsigned long lastDs18b20ReadingTime = 0; // the last time the DS18B20 sensor was read
  64. unsigned long dhtDelay = 2000; //delay so sensor is read every 2 seconds
  65. unsigned long lastDhtReadingTime = 0; // the last time the DHT22 was read
  66. unsigned long layLightTimer = 36000000; // Timer to make sure at least 14 hours or "daylight"
  67. unsigned long lastDayLightReadingTime = 0; // timer to keep track of how long it has been night
  68. unsigned long nightLightDelay = 300000; // 5 minute timer to turn on the coop light if "enter" is pushed and it is night.
  69. unsigned long lastNightLightTime = 0; // the last time the night light button was pushed
  70. unsigned long photocellReadingDelay = 600000; // 600000 = 10 minute
  71. unsigned long lastPhotocellReadingTime = 0; // the last time the photocell was read
  72.  
  73. // Sensor Variables
  74. bool doorOpen = true; // is the coop door open
  75. bool doorClosed = false; // is the door closed
  76. bool doorOpenMove = false; // is the door opening?
  77. bool doorCloseMove = false; // is the door closing?
  78. int topSwitchState; // Current state (open/closed) of the top limit switch
  79. int bottomSwitchState; // Current state (open/closed) of the bottom limit switch
  80. bool ventOn = false; // is the ventilation fan relay on or off
  81. bool heaterOn = false; // is the water heater relay on or off
  82. bool nightTimer = false; // is it night time
  83. bool layLightOn = true; // is the Lay Light time monitoring system on
  84. bool nightLightOn = false; // is the Night Light on
  85. int coopTemp = 0; // Interior Coop Temperature Reading
  86. int closeDoor = 30; // Light level to close coop door (user editable, EEPROM saved)
  87. int hotTemp = 30; // Temperature to turn on Ventilation Fan Relay (user editable, EEPROM saved)
  88. int coldTemp = 3; // Temperature to turn on Water Heat Relay (user editable, EEPROM saved)
  89. int waterTemp = 0; // Water Tempterature Reading
  90. float hum; // Stores humidity value from DHT22
  91. float temp; // Stores temperature value from DHT22
  92. int photocellReading; // analog reading of the photocell
  93. int photocellReadingLevel = '2'; // photocell reading levels (night, light, twilight)
  94.  
  95. // UART Communication
  96. char camRx; // Command Character Received from ESP32-Cam
  97. char coopTx; //Communication From Coop Command
  98. bool newDataRx = false; //Has CoopCommand received a new command from the ESP32-Cam?
  99. unsigned long serialDelay = 30000; //delay to send coop status updates
  100. unsigned long lastSerialSend = 0; //the last time an update was sent
  101.  
  102.  
  103. // Human Machine Interface Variables
  104. bool menuOn = true; // state of the display menu
  105. int buttonState1 = 0; // current state of button1
  106. int buttonState2 = 0; // current state of button2
  107. int buttonState3 = 0; // current state of button3
  108. int lastButtonState1 = 0; // previous state of button1
  109. int lastButtonState2 = 0; // previous state of button2
  110. int lastButtonState3 = 0; // previous state of button3
  111. unsigned long displayTimer = 8000; // timer to automatically turn off the display
  112. unsigned long lastDisplayTimer = 0; // last time the turn off delay was re-set
  113. int optionSelect = 0; // which menu option is selected
  114. int lastOptionSelect = 0; // the last menu option that was selected
  115. int lastItemSelect = 0; // which menu item is selected
  116. int itemSelect = 0; // which menu item was selected last
  117.  
  118. //EEPROM addresses and variables
  119.  
  120. int coldTempAddress = 0; // EEPROM address for the water heat turn on temperature
  121. int hotTempAddress = 1; // EEPROM address for the ventilation fan turn on temperature
  122. int closeDoorAddress = 2; // EEPROM address for the door close light level
  123.  
  124.  
  125.  
  126. void setup() {
  127. // put your setup code here, to run once:
  128. dht.begin();
  129. sensors.begin();
  130. Serial.begin(115200);
  131. coldTemp = EEPROM.read(0);
  132. hotTemp = EEPROM.read(1);
  133. closeDoor = EEPROM.read(2);
  134. pinMode(photocellPin, INPUT);
  135. pinMode(button1, INPUT);
  136. pinMode(button2, INPUT);
  137. pinMode(button3, INPUT);
  138. pinMode(topSwitchPin, INPUT);
  139. pinMode(bottomSwitchPin, INPUT);
  140. pinMode(layLightRelay, OUTPUT);
  141. pinMode(fanRelay, OUTPUT);
  142. pinMode(fanLED, OUTPUT);
  143. pinMode(motorLED, OUTPUT);
  144. pinMode(heatLED, OUTPUT);
  145. pinMode(heatRelay, OUTPUT);
  146. pinMode(directionCloseCoopDoorMotorB, OUTPUT);
  147. pinMode(directionOpenCoopDoorMotorB, OUTPUT);
  148. lcd.begin();
  149. lcd.clear();
  150. lcd.home();
  151. lcd.print(" Coop Command");
  152. lcd.setCursor(0, 1);
  153. lcd.print(" Control Center");
  154. lcd.setCursor(0, 2);
  155. lcd.print(" WI-FI V1.2");
  156. lcd.setCursor(0, 3);
  157. lcd.print(" LOADING...");
  158. delay(2000);
  159. lcd.clear();
  160. photocellReading = analogRead(photocellPin);
  161. EEPROM.write(coldTempAddress, 3);
  162. EEPROM.write(hotTempAddress, 30);
  163. EEPROM.write(closeDoorAddress, 30);
  164. }
  165.  
  166. // Function to Communicate with ESP32-CAM
  167. void camCommand() {
  168. if (Serial.available() > 0) {
  169. camRx = Serial.read();
  170. newDataRx = true;
  171. }
  172. if (newDataRx == true) {
  173. if (camRx == 'U') { //If the ESP32 says to put the door up
  174. photocellReadingLevel = '3';
  175. lastPhotocellReadingTime = millis();
  176. newDataRx = false;
  177. }
  178. if (camRx == 'D') { //If the ESP32 says to put the door down
  179. photocellReadingLevel = '1';
  180. lastPhotocellReadingTime = millis();
  181. newDataRx = false;
  182. }
  183. }
  184. if ((unsigned long)(millis() - lastSerialSend) >= serialDelay) {
  185. lastSerialSend = millis();
  186. if (doorClosed) { // If door is closed
  187. Serial.print('S');
  188. }
  189. if (doorOpen) { // If door is open
  190. Serial.print('O');
  191. }
  192. if (doorOpenMove) { //If door is opening
  193. Serial.print('U');
  194. }
  195. if (doorCloseMove) { //If door is closing
  196. Serial.print('D');
  197. }
  198. }
  199. }
  200.  
  201. // Function to Control Ventilation Fan Relay
  202. void ventFan() {
  203. if ((unsigned long)(millis() - lastDhtReadingTime) >= dhtDelay) {
  204. lastDhtReadingTime = millis();
  205. hum = dht.readHumidity();
  206. temp = dht.readTemperature();
  207. coopTemp = temp;
  208. if (coopTemp >= hotTemp) { // if the temperature is above the Hot temperature
  209. digitalWrite(fanRelay, HIGH);
  210. digitalWrite(fanLED, HIGH);
  211. ventOn = true;
  212. }
  213. else if (coopTemp < (hotTemp - 2)) { // if the temperature has been lowered two degrees
  214. digitalWrite(fanRelay, LOW);
  215. digitalWrite(fanLED, LOW);
  216. ventOn = false;
  217. }
  218. }
  219. }
  220.  
  221. // Function to Control LayLight and NightLight Relay
  222. void layLight() {
  223. if (layLightOn) {
  224. if (!nightTimer) { // if it is not dark
  225. lastDayLightReadingTime = millis();
  226. digitalWrite(layLightRelay, LOW); // turn off the lay light
  227. }
  228. if (nightTimer) { // if it is dark
  229. if ((unsigned long)(millis() - lastDayLightReadingTime) >= layLightTimer) { //if it has been dark more than 10 hours (or whatever the timer is
  230. digitalWrite(layLightRelay, HIGH); // turn on the lay light
  231. }
  232. else {
  233. digitalWrite(layLightRelay, LOW); // turn off the lay light
  234. }
  235. }
  236. }
  237. if (nightLightOn) { // if someone wants the light on
  238. digitalWrite(layLightRelay, HIGH);
  239. }
  240. if ((unsigned long)(millis() - lastNightLightTime) >= nightLightDelay) {
  241. digitalWrite (layLightRelay, LOW);
  242. nightLightOn = false;
  243. }
  244. }
  245.  
  246. // Function to Control Water Heat Relay
  247. void waterHeat() {
  248. if ((unsigned long)(millis() - lastDs18b20ReadingTime) >= ds18b20Delay) {
  249. lastDs18b20ReadingTime = millis();
  250. sensors.requestTemperatures();
  251. waterTemp = sensors.getTempCByIndex(0);
  252. if (waterTemp >= (coldTemp + 3)) { // if the temperature is 3 degrees above the trigger temp
  253. digitalWrite(heatRelay, LOW); //turn off the water heater
  254. digitalWrite(heatLED, LOW); // turn off the LED indicator
  255. heaterOn = false;
  256. }
  257. else if (waterTemp < coldTemp) { //if the temperature is below the cold temperature
  258. digitalWrite(heatRelay, HIGH); //turn on the water heater
  259. digitalWrite(heatLED, HIGH); // turn on the LED indicator
  260. heaterOn = true;
  261. }
  262. }
  263. }
  264.  
  265. // Function to Monitor Light Levels
  266. void photoCell() { // function to be called repeatedly - per coopPhotoCellTimer set in setup
  267. if ((unsigned long)(millis() - lastPhotocellReadingTime) >= photocellReadingDelay) {
  268. photocellReading = analogRead(photocellPin);
  269. lastPhotocellReadingTime = millis();
  270.  
  271. // set photocell threshholds
  272. if (photocellReading >= 0 && photocellReading <= closeDoor) { // Night Setting based on user or default selected low light trigger
  273. photocellReadingLevel = '1';
  274. nightTimer = true;
  275. }
  276.  
  277. else if (photocellReading >= closeDoor && photocellReading <= 125) { // Twighlight setting
  278. photocellReadingLevel = '2';
  279. nightTimer = true;
  280. }
  281.  
  282. else if (photocellReading >= 126 ) { //Daylight Setting
  283. photocellReadingLevel = '3';
  284. nightTimer = false;
  285. }
  286. }
  287. }
  288.  
  289.  
  290. // stop the coop door motor and put the motor driver IC to sleep (power saving)
  291. void stopCoopDoorMotorB() {
  292. digitalWrite (directionCloseCoopDoorMotorB, LOW); // turn off motor close direction
  293. digitalWrite (directionOpenCoopDoorMotorB, LOW); // turn off motor open direction
  294. digitalWrite(motorLED, LOW);
  295. }
  296.  
  297.  
  298.  
  299. // close the coop door motor
  300. void closeCoopDoorMotorB() {
  301. if (bottomSwitchState == 1) { //if the bottom reed switch is open
  302. digitalWrite (directionCloseCoopDoorMotorB, HIGH); // turn on motor close direction
  303. digitalWrite (directionOpenCoopDoorMotorB, LOW); // turn off motor open direction
  304. digitalWrite(motorLED, HIGH);
  305. }
  306. if ((bottomSwitchState == 1) && (topSwitchState == 1)) { // if both reed switches are open
  307. doorCloseMove = true;
  308. doorOpenMove = false;
  309. doorOpen = false;
  310. doorClosed = false;
  311. }
  312.  
  313. else if (bottomSwitchState == 0) { // if bottom reed switch circuit is closed
  314. stopCoopDoorMotorB();
  315. doorOpenMove = false;
  316. doorCloseMove = false;
  317. doorOpen = false;
  318. doorClosed = true;
  319. }
  320. }
  321.  
  322.  
  323.  
  324. // open the coop door
  325. void openCoopDoorMotorB() {
  326. if (topSwitchState == 1) { //if the top reed switch is open
  327. digitalWrite(directionCloseCoopDoorMotorB, LOW); // turn off motor close direction
  328. digitalWrite(directionOpenCoopDoorMotorB, HIGH); // turn on motor open direction
  329. digitalWrite(motorLED, HIGH);
  330. }
  331. if ((bottomSwitchState == 1) && (topSwitchState == 1)) { // if both reed switches are open
  332. doorCloseMove = false;
  333. doorOpenMove = true;
  334. doorOpen = false;
  335. doorClosed = false;
  336. }
  337. else if (topSwitchState == 0) { // if top reed switch circuit is closed
  338. stopCoopDoorMotorB();
  339. doorOpenMove = false;
  340. doorCloseMove = false;
  341. doorOpen = true;
  342. doorClosed = false;
  343. }
  344. }
  345.  
  346.  
  347. void readSwitches() {
  348. topSwitchState = (digitalRead(topSwitchPin));
  349. bottomSwitchState = (digitalRead(bottomSwitchPin));
  350. }
  351.  
  352. // do the coop door
  353. void doCoopDoor() {
  354. if (photocellReadingLevel == '1') { // if it's dark
  355. if (photocellReadingLevel != '2') { // if it's not twilight
  356. if (photocellReadingLevel != '3') { // if it's not light
  357. readSwitches();
  358. closeCoopDoorMotorB(); // close the door
  359. }
  360. }
  361. }
  362. if (photocellReadingLevel == '3') { // if it's light
  363. if (photocellReadingLevel != '2') { // if it's not twilight
  364. if (photocellReadingLevel != '1') { // if it's not dark
  365. readSwitches();
  366. openCoopDoorMotorB(); // Open the door
  367. }
  368. }
  369. }
  370. else if (photocellReadingLevel == '2') { // if it's twilight
  371. if (photocellReadingLevel != '3') { // if it's not light
  372. if (photocellReadingLevel != '1') { // if it's not dark
  373. readSwitches();
  374. stopCoopDoorMotorB();
  375. }
  376. }
  377. }
  378. }
  379.  
  380.  
  381. void readButtons() {
  382. buttonState1 = (digitalRead(button1));
  383. buttonState2 = (digitalRead(button2));
  384. buttonState3 = (digitalRead(button3));
  385. if (buttonState1 != lastButtonState1) {
  386. if (buttonState1 == LOW) { //if the enter/back button has been pressed
  387. lastDisplayTimer = millis();
  388. if ((itemSelect == 0) && (optionSelect != 0)) { //if we are not in the settings change
  389. itemSelect = 1;
  390. }
  391. else if (itemSelect == 1) {
  392. itemSelect = 0;
  393. }
  394. }
  395. lastButtonState1 = buttonState1;
  396. }
  397. if (itemSelect == 0) { // if we are not adjusting settings
  398.  
  399. if (buttonState3 != lastButtonState3) { //if the right button has been pressed
  400. if (buttonState3 == LOW) { //if the right button has been pressed
  401. lastDisplayTimer = millis();
  402. if ((optionSelect <= 5) && (optionSelect != 5)) { //if we are not past the last menu screen
  403. optionSelect ++;
  404. }
  405. else if (optionSelect == 5) { // if we are at the last menu screen
  406. optionSelect = 0;
  407. }
  408. }
  409. lastButtonState3 = buttonState3;
  410. }
  411. if (buttonState2 != lastButtonState2) { //if the left button has been pressed
  412. if (buttonState2 == LOW) { //if the left button has been pressed
  413. lastDisplayTimer = millis();
  414. if (optionSelect > 0) { //if we are not at the first menu screen
  415. optionSelect --;
  416. }
  417. else if (optionSelect == 0) {
  418. optionSelect = 5;
  419. }
  420. }
  421. lastButtonState2 = buttonState2;
  422. }
  423. }
  424.  
  425. else if (itemSelect == 1) { // if we are adjusting settings
  426. buttonState2 = (digitalRead(button2));
  427. buttonState3 = (digitalRead(button3));
  428.  
  429. if (buttonState3 != lastButtonState3) { //if the right button has been pressed
  430. if (buttonState3 == LOW) { //if the right button has been pressed
  431. lastDisplayTimer = millis();
  432. if (optionSelect == 1) { //if we are adjusting the Vent Fan Temp
  433. hotTemp = (hotTemp + 5);
  434. }
  435. else if (optionSelect == 2) { // if we are adjusting the Water Heater Temp
  436. coldTemp = (coldTemp + 1);
  437. }
  438. else if (optionSelect == 3) { // if we are adjusting the Door Light Sensor
  439. closeDoor = (closeDoor + 5);
  440. }
  441. }
  442. lastButtonState3 = buttonState3;
  443. }
  444. if (buttonState2 != lastButtonState2) { //if the left button has been pressed
  445. if (buttonState2 == LOW) { //if the left button has been pressed
  446. lastDisplayTimer = millis();
  447. if (optionSelect == 1) { //if we are adjusting the Vent Fan Temp
  448. hotTemp = (hotTemp - 5);
  449. }
  450. else if (optionSelect == 2) { // if we are adjusting the Water Heater Temp
  451. coldTemp = (coldTemp - 1);
  452. }
  453. else if (optionSelect == 3) { // if we are adjusting the Door Light Sensor
  454. closeDoor = (closeDoor - 5);
  455. }
  456. }
  457. lastButtonState2 = buttonState2;
  458. }
  459. if (optionSelect == 4) { // if we are overriding the coop door
  460. if (doorOpen) { // if the coop door is open
  461. itemSelect = 0;
  462. optionSelect = 0; //back to front screen
  463. lastPhotocellReadingTime = millis();
  464. lastDisplayTimer = millis();
  465. photocellReadingLevel = '1';
  466.  
  467. }
  468. else if (!doorOpen) { //if the coop door is closed
  469. itemSelect = 0;
  470. optionSelect = 0; //back to front screen
  471. lastDisplayTimer = millis();
  472. lastPhotocellReadingTime = millis();
  473. photocellReadingLevel = '3';
  474. }
  475. }
  476. if (optionSelect == 5) { // if we are turning the laylight option on/off
  477. if (layLightOn) { // if the lay light option is on
  478. itemSelect = 0;
  479. optionSelect = 0; //back to front screen
  480. lastDisplayTimer = millis();
  481. layLightOn = false;
  482. }
  483. else if (!layLightOn) { //if the lay light option is off
  484. itemSelect = 0;
  485. optionSelect = 0; //back to front screen
  486. lastDisplayTimer = millis();
  487. layLightOn = true;
  488. }
  489. }
  490. }
  491. }
  492.  
  493. void displayMenu() {
  494. if (menuOn) { // if the display is supposed to be on
  495. lcd.display(); // turn the display on
  496. lcd.backlight();
  497.  
  498. if (optionSelect != lastOptionSelect) {
  499. lcd.clear();
  500. lastOptionSelect = optionSelect;
  501. }
  502. else if (itemSelect != lastItemSelect) {
  503. lcd.clear();
  504. lastItemSelect = itemSelect;
  505. }
  506.  
  507. switch (optionSelect) {
  508.  
  509. case 0:
  510. lcd.home();
  511. lcd.print(" Coop Command");
  512. lcd.setCursor(0, 1);
  513. lcd.print("< >");
  514. lcd.setCursor(0, 2);
  515. lcd.print(" Control Center");
  516. lcd.setCursor(0, 3);
  517. lcd.print("WI-FI Firmware V1.2");
  518. break;
  519.  
  520. case 1:
  521. if (itemSelect == 0 && ventOn == false) {
  522. lcd.home();
  523. lcd.print(" Coop Temp: ");
  524. lcd.print(coopTemp);
  525. lcd.print(" C");
  526. lcd.setCursor(0, 1);
  527. lcd.print("< >");
  528. lcd.setCursor(0, 2);
  529. lcd.print(" Ventilation Fan: ");
  530. lcd.setCursor(7, 3);
  531. lcd.print("OFF");
  532. }
  533. else if (itemSelect == 0 && ventOn == true) {
  534. lcd.home();
  535. lcd.print(" Coop Temp: ");
  536. lcd.print(coopTemp);
  537. lcd.print(" C");
  538. lcd.setCursor(0, 1);
  539. lcd.print("< >");
  540. lcd.setCursor(0, 2);
  541. lcd.print(" Ventilation Fan: ");
  542. lcd.setCursor(7, 3);
  543. lcd.print(" ON");
  544. }
  545. if (itemSelect == 1) {
  546. lcd.home();
  547. lcd.print(" Coop Temp: ");
  548. lcd.print(coopTemp);
  549. lcd.print(" C");
  550. lcd.setCursor(0, 1);
  551. lcd.print("< >");
  552. lcd.setCursor(1, 2);
  553. lcd.print("Fan On Temp: ");
  554. lcd.print(hotTemp);
  555. lcd.print(" C");
  556. }
  557. break;
  558.  
  559. case 2:
  560. if (itemSelect == 0 && heaterOn == false) {
  561. lcd.home();
  562. lcd.print(" Water Temp: ");
  563. lcd.print(waterTemp);
  564. lcd.print(" C");
  565. lcd.setCursor(0, 1);
  566. lcd.print("< >");
  567. lcd.setCursor(4, 2);
  568. lcd.print("Water Heat: ");
  569. lcd.setCursor(7, 3);
  570. lcd.print("OFF");
  571. }
  572. else if (itemSelect == 0 && heaterOn == true) {
  573. lcd.home();
  574. lcd.print(" Water Temp: ");
  575. lcd.print(waterTemp);
  576. lcd.print(" C");
  577. lcd.setCursor(0, 1);
  578. lcd.print("< >");
  579. lcd.setCursor(4, 2);
  580. lcd.print("Water Heat: ");
  581. lcd.setCursor(7, 3);
  582. lcd.print("ON");
  583. }
  584. if (itemSelect == 1) {
  585. lcd.home();
  586. lcd.print(" Water Temp: ");
  587. lcd.print(waterTemp);
  588. lcd.print(" C");
  589. lcd.setCursor(0, 1);
  590. lcd.print("< >");
  591. lcd.setCursor(1, 2);
  592. lcd.print("Heat On Temp: ");
  593. lcd.print(coldTemp);
  594. lcd.print(" C");
  595. }
  596. break;
  597.  
  598. case 3:
  599. if (itemSelect == 0 && doorOpen == true) {
  600. lcd.home();
  601. lcd.print(" Coop Door: ");
  602. lcd.print("OPEN");
  603. lcd.setCursor(0, 1);
  604. lcd.print("< >");
  605. lcd.setCursor(3, 2);
  606. lcd.print("Light Value: ");
  607. lcd.setCursor(7, 3);
  608. lcd.print(photocellReading);
  609. }
  610. else if (itemSelect == 0 && doorClosed == true) {
  611. lcd.home();
  612. lcd.print(" Coop Door: ");
  613. lcd.print("CLOSED");
  614. lcd.setCursor(0, 1);
  615. lcd.print("< >");
  616. lcd.setCursor(3, 2);
  617. lcd.print("Light Value: ");
  618. lcd.setCursor(7, 3);
  619. lcd.print(photocellReading);
  620. }
  621. if (itemSelect == 1 && doorOpen == true) {
  622. lcd.home();
  623. lcd.print(" Coop Door: ");
  624. lcd.print("OPEN");
  625. lcd.setCursor(0, 1);
  626. lcd.print("< >");
  627. lcd.setCursor(2, 2);
  628. lcd.print("Light Adjust: ");
  629. lcd.print(closeDoor);
  630. }
  631. if (itemSelect == 1 && doorClosed == true) {
  632. lcd.home();
  633. lcd.print(" Coop Door: ");
  634. lcd.print("CLOSED");
  635. lcd.setCursor(0, 1);
  636. lcd.print("< >");
  637. lcd.setCursor(2, 2);
  638. lcd.print("Light Adjust: ");
  639. lcd.print(closeDoor);
  640. }
  641. break;
  642.  
  643. case 4:
  644. if (itemSelect == 0 && doorOpen == true) {
  645. lcd.home();
  646. lcd.print(" Door OVERRIDE:");
  647. lcd.setCursor(0, 1);
  648. lcd.print("< OPEN >");
  649. lcd.setCursor(0, 3);
  650. lcd.print("Click ENTER to Close");
  651. }
  652. else if (itemSelect == 0 && doorClosed == true) {
  653. lcd.home();
  654. lcd.print(" Door OVERRIDE:");
  655. lcd.setCursor(0, 1);
  656. lcd.print("< CLOSED >");
  657. lcd.setCursor(0, 3);
  658. lcd.print("Click ENTER to Open");
  659. }
  660. break;
  661.  
  662. case 5:
  663. if (itemSelect == 0 && layLightOn == true) {
  664. lcd.home();
  665. lcd.print(" LayLight Timer:");
  666. lcd.setCursor(0, 1);
  667. lcd.print("< ON >");
  668. lcd.setCursor(0, 3);
  669. lcd.print(" ENTER to turn OFF");
  670. }
  671. else if (itemSelect == 0 && layLightOn == false) {
  672. lcd.home();
  673. lcd.print(" LayLight Timer:");
  674. lcd.setCursor(0, 1);
  675. lcd.print("< OFF >");
  676. lcd.setCursor(0, 3);
  677. lcd.print(" ENTER to turn ON");
  678. }
  679. break;
  680. }
  681.  
  682. if ((unsigned long)(millis() - lastDisplayTimer) >= displayTimer) {
  683. menuOn = false;
  684. }
  685. }
  686. else if (!menuOn) { // if the display is supposed to be off
  687. lcd.noDisplay(); // turn the display off
  688. lcd.noBacklight();
  689. optionSelect = 0; //back to front screen
  690. itemSelect = 0;
  691. }
  692. if ((buttonState1 == 0) && (!menuOn)) {
  693. menuOn = true;
  694. lastDisplayTimer = millis();
  695. optionSelect = 0; //back to front screen
  696. itemSelect = 0;
  697. if (nightTimer) {
  698. nightLightOn = true;
  699. lastNightLightTime = millis();
  700. }
  701. }
  702. }
  703.  
  704. void settingSave() {
  705. EEPROM.update(hotTempAddress, hotTemp);
  706. EEPROM.update(coldTempAddress, coldTemp);
  707. EEPROM.update(closeDoorAddress, closeDoor);
  708. }
  709.  
  710. void humanInterface() {
  711. readButtons();
  712. displayMenu();
  713. camCommand();
  714. }
  715.  
  716. void coopOperation() {
  717. settingSave();
  718. ventFan();
  719. photoCell();
  720. doCoopDoor();
  721. waterHeat();
  722. layLight();
  723. }
  724.  
  725. void loop() {
  726.  
  727. humanInterface();
  728. coopOperation();
  729. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement