Advertisement
hms11

CoopCommandRev2

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