manhoosbilli1

all code except motor

Jul 17th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <TimeLib.h>
  4. #include <TimeAlarms.h>
  5. #include <Bounce2.h>
  6. #include "DHT.h"
  7. #define DHTPIN 7 // what pin we're connected to
  8. #define DHTTYPE DHT22 // DHT 22 (AM2302)
  9. #define btn_up 11
  10. #define btn_down 12
  11. #define btn_select 10
  12. bool Up;
  13. bool Down;
  14. bool Select;
  15. bool updAlarm;
  16. float h;
  17. float t;
  18. DHT dht(DHTPIN, DHTTYPE);
  19. LiquidCrystal_I2C lcd(0x27, 16, 2);
  20. AlarmId id;
  21. Bounce debouncer1 = Bounce();
  22. Bounce debouncer2 = Bounce();
  23. Bounce debouncer3 = Bounce();
  24.  
  25.  
  26. void setup() {
  27. // put your setup code here, to run once:
  28. pinMode(btn_up,INPUT_PULLUP);
  29. debouncer1.attach(btn_up);
  30. debouncer1.interval(25); // interval in ms
  31. pinMode(btn_down,INPUT_PULLUP);
  32. debouncer2.attach(btn_down);
  33. debouncer2.interval(25);
  34. pinMode(btn_select,INPUT_PULLUP);
  35. debouncer3.attach(btn_select);
  36. debouncer3.interval(25);
  37. //add a function that will read sensors after every 2 seconds
  38. dht.begin();
  39.  
  40. //ask if the user wants to start incubating procedure if
  41. //not already in the process
  42. lcd.begin();
  43. lcd.backlight();
  44. lcd.setCursor(0,0);
  45. lcd.print(" Incubator ");
  46. lcd.setCursor(0,1);
  47. lcd.print(" Starting ");
  48. Alarm.delay(2000);
  49. }
  50. enum pages {
  51. DEFAULT_SENSOR,
  52. MANUAL_MTR_TURN,
  53. MOTOR_DEMO,
  54. TOGGLE_BUZZER,
  55. SHOW_TIME,
  56. CALCULATE_HATCHDATE
  57. };
  58. int currentPage = DEFAULT_SENSOR;
  59. void loop() {
  60. updateSwitches();
  61. Up = debouncer1.read();
  62. Down = debouncer2.read();
  63. Select = debouncer3.read();
  64. menu();
  65.  
  66.  
  67. }
  68.  
  69.  
  70. void updateSwitches(){
  71. Up = debouncer1.read();
  72. Down = debouncer2.read();
  73. Select = debouncer3.read();
  74. }
  75.  
  76.  
  77.  
  78. void menu() {
  79. switch(currentPage) {
  80. case DEFAULT_SENSOR:
  81. updateSwitches();
  82. lcd.setCursor(0,0);
  83. lcd.print(" T: ");
  84. //show temperature from sensor
  85. lcd.print("38*C");
  86. lcd.setCursor(0,1);
  87. lcd.print(" H: ");
  88. lcd.print("56%");
  89. lcd.print(" ");
  90. if(debouncer1.fell()) { //up is pressed
  91. currentPage = CALCULATE_HATCHDATE;
  92. }
  93. if(debouncer2.fell()){
  94. currentPage = SHOW_TIME;
  95. }
  96. //show humidity from sensor
  97. break;
  98.  
  99. case CALCULATE_HATCHDATE:
  100. updateSwitches();
  101. lcd.setCursor(0,0);
  102. lcd.print("Press Select To ");
  103. lcd.setCursor(0,1);
  104. lcd.print("Find HatchDay ");
  105. if(debouncer1.fell()) { //up is pressed
  106. currentPage = MANUAL_MTR_TURN;
  107. }
  108. if(debouncer2.fell()){
  109. currentPage = DEFAULT_SENSOR;
  110. }
  111. break;
  112.  
  113. case MANUAL_MTR_TURN:
  114. updateSwitches();
  115. lcd.setCursor(0,0);
  116. lcd.print("Press Select ");
  117. lcd.setCursor(0,1);
  118. lcd.print("To Turn Motor ");
  119.  
  120. break;
  121.  
  122. case MOTOR_DEMO:
  123. updateSwitches();
  124. lcd.setCursor(0,0);
  125. lcd.print("Press Select ");
  126. lcd.setCursor(0,1);
  127. lcd.print("To Run Demo ");
  128.  
  129. break;
  130.  
  131. case TOGGLE_BUZZER:
  132. updateSwitches();
  133. lcd.setCursor(0,0);
  134. lcd.print("Press Select ");
  135. lcd.setCursor(0,1);
  136. lcd.print("To toggle ");
  137.  
  138. break;
  139.  
  140.  
  141. case SHOW_TIME:
  142. updateSwitches();
  143. lcd.setCursor(0,0);
  144. lcd.print("Press Select ");
  145. lcd.setCursor(0,1);
  146. lcd.print("To Show Time ");
  147.  
  148. break;
  149.  
  150. }
  151. }
  152.  
  153.  
  154.  
  155. void updateBuzzer(){
  156. }
  157.  
  158. void countDownForHatch(){
  159. }
Add Comment
Please, Sign In to add comment