Advertisement
hms11

CoopCommand Wifi Rev1.2 Rev2

Apr 18th, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.52 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. coldTemp = EEPROM.read(0);
  129. hotTemp = EEPROM.read(1);
  130. closeDoor = EEPROM.read(2);
  131. dht.begin();
  132. sensors.begin();
  133. Serial.begin(115200);
  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. }
  162.  
  163. // Function to Communicate with ESP32-CAM
  164. void camCommand() {
  165. if (Serial.available() > 0) {
  166. camRx = Serial.read();
  167. newDataRx = true;
  168. }
  169. if (newDataRx == true) {
  170. if (camRx == 'U') { //If the ESP32 says to put the door up
  171. photocellReadingLevel = '3';
  172. lastPhotocellReadingTime = millis();
  173. newDataRx = false;
  174. }
  175. else if (camRx == 'D') { //If the ESP32 says to put the door down
  176. photocellReadingLevel = '1';
  177. lastPhotocellReadingTime = millis();
  178. newDataRx = false;
  179. }
  180. }
  181. if ((unsigned long)(millis() - lastSerialSend) >= serialDelay) {
  182. lastSerialSend = millis();
  183. if (doorClosed) { // If door is closed
  184. Serial.print('S');
  185. }
  186. else if (doorOpen) { // If door is open
  187. Serial.print('O');
  188. }
  189. else if (doorOpenMove) { //If door is opening
  190. Serial.print('U');
  191. }
  192. else if (doorCloseMove) { //If door is closing
  193. Serial.print('D');
  194. }
  195. }
  196. }
  197.  
  198. // Function to Control Ventilation Fan Relay
  199. void ventFan() {
  200. if ((unsigned long)(millis() - lastDhtReadingTime) >= dhtDelay) {
  201. lastDhtReadingTime = millis();
  202. hum = dht.readHumidity();
  203. temp = dht.readTemperature();
  204. coopTemp = temp;
  205. if (coopTemp >= hotTemp) { // if the temperature is above the Hot temperature
  206. digitalWrite(fanRelay, HIGH);
  207. digitalWrite(fanLED, HIGH);
  208. ventOn = true;
  209. }
  210. else if (coopTemp < (hotTemp - 2)) { // if the temperature has been lowered two degrees
  211. digitalWrite(fanRelay, LOW);
  212. digitalWrite(fanLED, LOW);
  213. ventOn = false;
  214. }
  215. }
  216. }
  217.  
  218. // Function to Control LayLight and NightLight Relay
  219. void layLight() {
  220. if (layLightOn) {
  221. if (!nightTimer) { // if it is not dark
  222. lastDayLightReadingTime = millis();
  223. digitalWrite(layLightRelay, LOW); // turn off the lay light
  224. }
  225. else if (nightTimer) { // if it is dark
  226. if ((unsigned long)(millis() - lastDayLightReadingTime) >= layLightTimer) { //if it has been dark more than 10 hours (or whatever the timer is
  227. digitalWrite(layLightRelay, HIGH); // turn on the lay light
  228. }
  229. else {
  230. digitalWrite(layLightRelay, LOW); // turn off the lay light
  231. }
  232. }
  233. }
  234. if (nightLightOn) { // if someone wants the light on
  235. digitalWrite(layLightRelay, HIGH);
  236. }
  237. else if ((unsigned long)(millis() - lastNightLightTime) >= nightLightDelay) {
  238. digitalWrite (layLightRelay, LOW);
  239. nightLightOn = false;
  240. }
  241. }
  242.  
  243. // Function to Control Water Heat Relay
  244. void waterHeat() {
  245. if ((unsigned long)(millis() - lastDs18b20ReadingTime) >= ds18b20Delay) {
  246. lastDs18b20ReadingTime = millis();
  247. sensors.requestTemperatures();
  248. waterTemp = sensors.getTempCByIndex(0);
  249. if (waterTemp >= (coldTemp + 3)) { // if the temperature is 3 degrees above the trigger temp
  250. digitalWrite(heatRelay, LOW); //turn off the water heater
  251. digitalWrite(heatLED, LOW); // turn off the LED indicator
  252. heaterOn = false;
  253. }
  254. else if (waterTemp < coldTemp) { //if the temperature is below the cold temperature
  255. digitalWrite(heatRelay, HIGH); //turn on the water heater
  256. digitalWrite(heatLED, HIGH); // turn on the LED indicator
  257. heaterOn = true;
  258. }
  259. }
  260. }
  261.  
  262. // Function to Monitor Light Levels
  263. void photoCell() { // function to be called repeatedly - per coopPhotoCellTimer set in setup
  264. if ((unsigned long)(millis() - lastPhotocellReadingTime) >= photocellReadingDelay) {
  265. photocellReading = analogRead(photocellPin);
  266. lastPhotocellReadingTime = millis();
  267.  
  268. // set photocell threshholds
  269. if (photocellReading >= 0 && photocellReading <= closeDoor) { // Night Setting based on user or default selected low light trigger
  270. photocellReadingLevel = '1';
  271. nightTimer = true;
  272. }
  273.  
  274. else if (photocellReading >= closeDoor && photocellReading <= 125) { // Twighlight setting
  275. photocellReadingLevel = '2';
  276. nightTimer = true;
  277. }
  278.  
  279. else if (photocellReading >= 126 ) { //Daylight Setting
  280. photocellReadingLevel = '3';
  281. nightTimer = false;
  282. }
  283. }
  284. }
  285.  
  286.  
  287. // stop the coop door motor and put the motor driver IC to sleep (power saving)
  288. void stopCoopDoorMotorB() {
  289. digitalWrite (directionCloseCoopDoorMotorB, LOW); // turn off motor close direction
  290. digitalWrite (directionOpenCoopDoorMotorB, LOW); // turn off motor open direction
  291. digitalWrite(motorLED, LOW);
  292. }
  293.  
  294.  
  295.  
  296. // close the coop door motor
  297. void closeCoopDoorMotorB() {
  298. if (bottomSwitchState == 1) { //if the bottom reed switch is open
  299. digitalWrite (directionCloseCoopDoorMotorB, HIGH); // turn on motor close direction
  300. digitalWrite (directionOpenCoopDoorMotorB, LOW); // turn off motor open direction
  301. digitalWrite(motorLED, HIGH);
  302. }
  303. if ((bottomSwitchState == 1) && (topSwitchState == 1)) { // if both reed switches are open
  304. doorCloseMove = true;
  305. doorOpenMove = false;
  306. doorOpen = false;
  307. doorClosed = false;
  308. }
  309.  
  310. if (bottomSwitchState == 0) { // if bottom reed switch circuit is closed
  311. stopCoopDoorMotorB();
  312. doorOpenMove = false;
  313. doorCloseMove = false;
  314. doorOpen = false;
  315. doorClosed = true;
  316. }
  317. }
  318.  
  319.  
  320.  
  321. // open the coop door
  322. void openCoopDoorMotorB() {
  323. if (topSwitchState == 1) { //if the top reed switch is open
  324. digitalWrite(directionCloseCoopDoorMotorB, LOW); // turn off motor close direction
  325. digitalWrite(directionOpenCoopDoorMotorB, HIGH); // turn on motor open direction
  326. digitalWrite(motorLED, HIGH);
  327. }
  328. if ((bottomSwitchState == 1) && (topSwitchState == 1)) { // if both reed switches are open
  329. doorCloseMove = false;
  330. doorOpenMove = true;
  331. doorOpen = false;
  332. doorClosed = false;
  333. }
  334. if (topSwitchState == 0) { // if top reed switch circuit is closed
  335. stopCoopDoorMotorB();
  336. doorOpenMove = false;
  337. doorCloseMove = false;
  338. doorOpen = true;
  339. doorClosed = false;
  340. }
  341. }
  342.  
  343.  
  344. void readSwitches() {
  345. topSwitchState = (digitalRead(topSwitchPin));
  346. bottomSwitchState = (digitalRead(bottomSwitchPin));
  347. }
  348.  
  349. // do the coop door
  350. void doCoopDoor() {
  351. if (photocellReadingLevel == '1') { // if it's dark
  352. if (photocellReadingLevel != '2') { // if it's not twilight
  353. if (photocellReadingLevel != '3') { // if it's not light
  354. readSwitches();
  355. closeCoopDoorMotorB(); // close the door
  356. }
  357. }
  358. }
  359. else if (photocellReadingLevel == '3') { // if it's light
  360. if (photocellReadingLevel != '2') { // if it's not twilight
  361. if (photocellReadingLevel != '1') { // if it's not dark
  362. readSwitches();
  363. openCoopDoorMotorB(); // Open the door
  364. }
  365. }
  366. }
  367. else if (photocellReadingLevel == '2') { // if it's twilight
  368. if (photocellReadingLevel != '3') { // if it's not light
  369. if (photocellReadingLevel != '1') { // if it's not dark
  370. readSwitches();
  371. stopCoopDoorMotorB();
  372. }
  373. }
  374. }
  375. }
  376.  
  377.  
  378. void readButtons() {
  379. buttonState1 = (digitalRead(button1));
  380. buttonState2 = (digitalRead(button2));
  381. buttonState3 = (digitalRead(button3));
  382. if (buttonState1 != lastButtonState1) {
  383. if (buttonState1 == LOW) { //if the enter/back button has been pressed
  384. lastDisplayTimer = millis();
  385. if ((itemSelect == 0) && (optionSelect != 0)) { //if we are not in the settings change
  386. itemSelect = 1;
  387. }
  388. else if (itemSelect == 1) {
  389. itemSelect = 0;
  390. }
  391. }
  392. lastButtonState1 = buttonState1;
  393. }
  394. if (itemSelect == 0) { // if we are not adjusting settings
  395.  
  396. if (buttonState3 != lastButtonState3) { //if the right button has been pressed
  397. if (buttonState3 == LOW) { //if the right button has been pressed
  398. lastDisplayTimer = millis();
  399. if ((optionSelect <= 5) && (optionSelect != 5)) { //if we are not past the last menu screen
  400. optionSelect ++;
  401. }
  402. else if (optionSelect == 5) { // if we are at the last menu screen
  403. optionSelect = 0;
  404. }
  405. }
  406. lastButtonState3 = buttonState3;
  407. }
  408. else if (buttonState2 != lastButtonState2) { //if the left button has been pressed
  409. if (buttonState2 == LOW) { //if the left button has been pressed
  410. lastDisplayTimer = millis();
  411. if (optionSelect > 0) { //if we are not at the first menu screen
  412. optionSelect --;
  413. }
  414. else if (optionSelect == 0) {
  415. optionSelect = 5;
  416. }
  417. }
  418. lastButtonState2 = buttonState2;
  419. }
  420. }
  421.  
  422. else if (itemSelect == 1) { // if we are adjusting settings
  423. buttonState2 = (digitalRead(button2));
  424. buttonState3 = (digitalRead(button3));
  425.  
  426. if (buttonState3 != lastButtonState3) { //if the right button has been pressed
  427. if (buttonState3 == LOW) { //if the right button has been pressed
  428. lastDisplayTimer = millis();
  429. if (optionSelect == 1) { //if we are adjusting the Vent Fan Temp
  430. hotTemp = (hotTemp + 5);
  431. }
  432. else if (optionSelect == 2) { // if we are adjusting the Water Heater Temp
  433. coldTemp = (coldTemp + 1);
  434. }
  435. else if (optionSelect == 3) { // if we are adjusting the Door Light Sensor
  436. closeDoor = (closeDoor + 5);
  437. }
  438. }
  439. lastButtonState3 = buttonState3;
  440. }
  441. else if (buttonState2 != lastButtonState2) { //if the left button has been pressed
  442. if (buttonState2 == LOW) { //if the left button has been pressed
  443. lastDisplayTimer = millis();
  444. if (optionSelect == 1) { //if we are adjusting the Vent Fan Temp
  445. hotTemp = (hotTemp - 5);
  446. }
  447. else if (optionSelect == 2) { // if we are adjusting the Water Heater Temp
  448. coldTemp = (coldTemp - 1);
  449. }
  450. else if (optionSelect == 3) { // if we are adjusting the Door Light Sensor
  451. closeDoor = (closeDoor - 5);
  452. }
  453. }
  454. lastButtonState2 = buttonState2;
  455. }
  456. if (optionSelect == 4) { // if we are overriding the coop door
  457. if (doorOpen) { // if the coop door is open
  458. itemSelect = 0;
  459. optionSelect = 0; //back to front screen
  460. lastPhotocellReadingTime = millis();
  461. lastDisplayTimer = millis();
  462. photocellReadingLevel = '1';
  463.  
  464. }
  465. else if (!doorOpen) { //if the coop door is closed
  466. itemSelect = 0;
  467. optionSelect = 0; //back to front screen
  468. lastDisplayTimer = millis();
  469. lastPhotocellReadingTime = millis();
  470. photocellReadingLevel = '3';
  471. }
  472. }
  473. if (optionSelect == 5) { // if we are turning the laylight option on/off
  474. if (layLightOn) { // if the lay light option is on
  475. itemSelect = 0;
  476. optionSelect = 0; //back to front screen
  477. lastDisplayTimer = millis();
  478. layLightOn = false;
  479. }
  480. else if (!layLightOn) { //if the lay light option is off
  481. itemSelect = 0;
  482. optionSelect = 0; //back to front screen
  483. lastDisplayTimer = millis();
  484. layLightOn = true;
  485. }
  486. }
  487. }
  488. }
  489.  
  490. void displayMenu() {
  491. if (menuOn) { // if the display is supposed to be on
  492. lcd.display(); // turn the display on
  493. lcd.backlight();
  494.  
  495. if (optionSelect != lastOptionSelect) {
  496. lcd.clear();
  497. lastOptionSelect = optionSelect;
  498. }
  499. if (itemSelect != lastItemSelect) {
  500. lcd.clear();
  501. lastItemSelect = itemSelect;
  502. }
  503.  
  504. switch (optionSelect) {
  505.  
  506. case 0:
  507. lcd.home();
  508. lcd.print(" Coop Command");
  509. lcd.setCursor(0, 1);
  510. lcd.print("< >");
  511. lcd.setCursor(0, 2);
  512. lcd.print(" Control Center");
  513. lcd.setCursor(0, 3);
  514. lcd.print("WI-FI Firmware V1.2");
  515. break;
  516.  
  517. case 1:
  518. if (itemSelect == 0 && ventOn == false) {
  519. lcd.home();
  520. lcd.print(" Coop Temp: ");
  521. lcd.print(coopTemp);
  522. lcd.print(" C");
  523. lcd.setCursor(0, 1);
  524. lcd.print("< >");
  525. lcd.setCursor(0, 2);
  526. lcd.print(" Ventilation Fan: ");
  527. lcd.setCursor(7, 3);
  528. lcd.print("OFF");
  529. }
  530. if (itemSelect == 0 && ventOn == true) {
  531. lcd.home();
  532. lcd.print(" Coop Temp: ");
  533. lcd.print(coopTemp);
  534. lcd.print(" C");
  535. lcd.setCursor(0, 1);
  536. lcd.print("< >");
  537. lcd.setCursor(0, 2);
  538. lcd.print(" Ventilation Fan: ");
  539. lcd.setCursor(7, 3);
  540. lcd.print(" ON");
  541. }
  542. if (itemSelect == 1) {
  543. lcd.home();
  544. lcd.print(" Coop Temp: ");
  545. lcd.print(coopTemp);
  546. lcd.print(" C");
  547. lcd.setCursor(0, 1);
  548. lcd.print("< >");
  549. lcd.setCursor(1, 2);
  550. lcd.print("Fan On Temp: ");
  551. lcd.print(hotTemp);
  552. lcd.print(" C");
  553. }
  554. break;
  555.  
  556. case 2:
  557. if (itemSelect == 0 && heaterOn == false) {
  558. lcd.home();
  559. lcd.print(" Water Temp: ");
  560. lcd.print(waterTemp);
  561. lcd.print(" C");
  562. lcd.setCursor(0, 1);
  563. lcd.print("< >");
  564. lcd.setCursor(4, 2);
  565. lcd.print("Water Heat: ");
  566. lcd.setCursor(7, 3);
  567. lcd.print("OFF");
  568. }
  569. if (itemSelect == 0 && heaterOn == true) {
  570. lcd.home();
  571. lcd.print(" Water Temp: ");
  572. lcd.print(waterTemp);
  573. lcd.print(" C");
  574. lcd.setCursor(0, 1);
  575. lcd.print("< >");
  576. lcd.setCursor(4, 2);
  577. lcd.print("Water Heat: ");
  578. lcd.setCursor(7, 3);
  579. lcd.print("ON");
  580. }
  581. if (itemSelect == 1) {
  582. lcd.home();
  583. lcd.print(" Water Temp: ");
  584. lcd.print(waterTemp);
  585. lcd.print(" C");
  586. lcd.setCursor(0, 1);
  587. lcd.print("< >");
  588. lcd.setCursor(1, 2);
  589. lcd.print("Heat On Temp: ");
  590. lcd.print(coldTemp);
  591. lcd.print(" C");
  592. }
  593. break;
  594.  
  595. case 3:
  596. if (itemSelect == 0 && doorOpen == true) {
  597. lcd.home();
  598. lcd.print(" Coop Door: ");
  599. lcd.print("OPEN");
  600. lcd.setCursor(0, 1);
  601. lcd.print("< >");
  602. lcd.setCursor(3, 2);
  603. lcd.print("Light Value: ");
  604. lcd.setCursor(7, 3);
  605. lcd.print(photocellReading);
  606. }
  607. if (itemSelect == 0 && doorClosed == true) {
  608. lcd.home();
  609. lcd.print(" Coop Door: ");
  610. lcd.print("CLOSED");
  611. lcd.setCursor(0, 1);
  612. lcd.print("< >");
  613. lcd.setCursor(3, 2);
  614. lcd.print("Light Value: ");
  615. lcd.setCursor(7, 3);
  616. lcd.print(photocellReading);
  617. }
  618. if (itemSelect == 0 && doorOpenMove == true) {
  619. lcd.home();
  620. lcd.print(" Coop Door: ");
  621. lcd.print("OPENING");
  622. lcd.setCursor(0, 1);
  623. lcd.print("< >");
  624. lcd.setCursor(3, 2);
  625. lcd.print("Light Value: ");
  626. lcd.setCursor(7, 3);
  627. lcd.print(photocellReading);
  628. }
  629. if (itemSelect == 0 && doorCloseMove == true) {
  630. lcd.home();
  631. lcd.print(" Coop Door: ");
  632. lcd.print("CLOSING");
  633. lcd.setCursor(0, 1);
  634. lcd.print("< >");
  635. lcd.setCursor(3, 2);
  636. lcd.print("Light Value: ");
  637. lcd.setCursor(7, 3);
  638. lcd.print(photocellReading);
  639. }
  640. if (itemSelect == 1 && doorOpen == true) {
  641. lcd.home();
  642. lcd.print(" Coop Door: ");
  643. lcd.print("OPEN");
  644. lcd.setCursor(0, 1);
  645. lcd.print("< >");
  646. lcd.setCursor(2, 2);
  647. lcd.print("Light Adjust: ");
  648. lcd.print(closeDoor);
  649. }
  650. if (itemSelect == 1 && doorClosed == true) {
  651. lcd.home();
  652. lcd.print(" Coop Door: ");
  653. lcd.print("CLOSED");
  654. lcd.setCursor(0, 1);
  655. lcd.print("< >");
  656. lcd.setCursor(2, 2);
  657. lcd.print("Light Adjust: ");
  658. lcd.print(closeDoor);
  659. }
  660. if (itemSelect == 1 && doorOpenMove == true) {
  661. lcd.home();
  662. lcd.print(" Coop Door: ");
  663. lcd.print("OPENING");
  664. lcd.setCursor(0, 1);
  665. lcd.print("< >");
  666. lcd.setCursor(2, 2);
  667. lcd.print("Light Adjust: ");
  668. lcd.print(closeDoor);
  669. }
  670. if (itemSelect == 1 && doorCloseMove == true) {
  671. lcd.home();
  672. lcd.print(" Coop Door: ");
  673. lcd.print("CLOSING");
  674. lcd.setCursor(0, 1);
  675. lcd.print("< >");
  676. lcd.setCursor(2, 2);
  677. lcd.print("Light Adjust: ");
  678. lcd.print(closeDoor);
  679. }
  680. break;
  681.  
  682. case 4:
  683. if (itemSelect == 0 && doorOpen == true) {
  684. lcd.home();
  685. lcd.print(" Door OVERRIDE:");
  686. lcd.setCursor(0, 1);
  687. lcd.print("< OPEN >");
  688. lcd.setCursor(0, 3);
  689. lcd.print("Click ENTER to Close");
  690. }
  691. if (itemSelect == 0 && doorClosed == true) {
  692. lcd.home();
  693. lcd.print(" Door OVERRIDE:");
  694. lcd.setCursor(0, 1);
  695. lcd.print("< CLOSED >");
  696. lcd.setCursor(0, 3);
  697. lcd.print("Click ENTER to Open");
  698. }
  699. if (itemSelect == 0 && doorCloseMove == true) {
  700. lcd.home();
  701. lcd.print(" Coop Door: ");
  702. lcd.print("CLOSING");
  703. }
  704. if (itemSelect == 0 && doorOpenMove == true) {
  705. lcd.home();
  706. lcd.print(" Coop Door: ");
  707. lcd.print("OPENING");
  708. }
  709. break;
  710.  
  711. case 5:
  712. if (itemSelect == 0 && layLightOn == true) {
  713. lcd.home();
  714. lcd.print(" LayLight Timer:");
  715. lcd.setCursor(0, 1);
  716. lcd.print("< ON >");
  717. lcd.setCursor(0, 3);
  718. lcd.print(" ENTER to turn OFF");
  719. }
  720. if (itemSelect == 0 && layLightOn == false) {
  721. lcd.home();
  722. lcd.print(" LayLight Timer:");
  723. lcd.setCursor(0, 1);
  724. lcd.print("< OFF >");
  725. lcd.setCursor(0, 3);
  726. lcd.print(" ENTER to turn ON");
  727. }
  728. break;
  729. }
  730.  
  731. if ((unsigned long)(millis() - lastDisplayTimer) >= displayTimer) {
  732. menuOn = false;
  733. }
  734. }
  735. if (!menuOn) { // if the display is supposed to be off
  736. lcd.noDisplay(); // turn the display off
  737. lcd.noBacklight();
  738. optionSelect = 0; //back to front screen
  739. itemSelect = 0;
  740. }
  741. if ((buttonState1 == 0) && (!menuOn)) {
  742. menuOn = true;
  743. lastDisplayTimer = millis();
  744. optionSelect = 0; //back to front screen
  745. itemSelect = 0;
  746. if (nightTimer) {
  747. nightLightOn = true;
  748. lastNightLightTime = millis();
  749. }
  750. }
  751. }
  752.  
  753. void settingSave() {
  754. EEPROM.update(hotTempAddress, hotTemp);
  755. EEPROM.update(coldTempAddress, coldTemp);
  756. EEPROM.update(closeDoorAddress, closeDoor);
  757. }
  758.  
  759. void humanInterface() {
  760. readButtons();
  761. displayMenu();
  762. camCommand();
  763. }
  764.  
  765. void coopOperation() {
  766. settingSave();
  767. ventFan();
  768. photoCell();
  769. doCoopDoor();
  770. waterHeat();
  771. layLight();
  772. }
  773.  
  774. void loop() {
  775.  
  776. humanInterface();
  777. coopOperation();
  778. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement