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