manhoosbilli1

all code except motor

Jul 10th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 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 12
  10. #define btn_down 11
  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. Alarm.timerRepeat(2, upd_alarm); //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. Alarm.delay(500);
  45. }
  46. enum pages {
  47. DEFAULT_SENSOR,
  48. MANUAL_MTR_TURN,
  49. MOTOR_DEMO,
  50. TOGGLE_BUZZER,
  51. SHOW_TIME,
  52. CALCULATE_HATCHDATE
  53. };
  54. int currentPage = DEFAULT_SENSOR;
  55. void loop() {
  56. debouncer1.update();
  57. debouncer2.update();
  58. debouncer3.update();
  59. int Up = debouncer1.read();
  60. int Down = debouncer2.read();
  61. int Select = debouncer3.read();
  62. menu();
  63.  
  64.  
  65. }
  66. void upd_alarm() { //function used in alarm to turn on flag for updating alarm
  67. updAlarm = true;
  68. }
  69.  
  70. void updateAlarm(){
  71. if(updAlarm == true)
  72. {
  73. //udate sensor
  74. h = dht.readHumidity();
  75. t = dht.readTemperature();
  76. if (isnan(h) || isnan(t)) {
  77. Serial.println("Failed to read from DHT sensor!");
  78. return;
  79. }
  80. updAlarm = false;
  81. }
  82. }
  83. void updatePage() {
  84. if(debouncer1.fell()) {
  85. if(currentPage == 0) {
  86. currentPage++;
  87. }
  88. if(currentPage == 5){
  89. currentPage = 0;
  90. }
  91. }
  92. if(debouncer3.fell()) {
  93. if(currentPage == 0){
  94. currentPage = 5;
  95. }
  96. if(currentPage == 5){
  97. currentPage--;
  98. }
  99. }
  100. }
  101.  
  102. void menu() {
  103. switch(currentPage) {
  104. case DEFAULT_SENSOR:
  105. //updateAlarms(); this will contain all the timers
  106. updateAlarm();
  107. lcd.setCursor(0,0);
  108. lcd.print(" T: ");
  109. //show temperature from sensor
  110. lcd.print(t);
  111. lcd.setCursor(0,1);
  112. lcd.print(" H: ");
  113. lcd.print(h);
  114. lcd.print(" ");
  115. updatePage();
  116. //show humidity from sensor
  117. break;
  118.  
  119. case CALCULATE_HATCHDATE:
  120. lcd.setCursor(0,0);
  121. lcd.print("Press Select To ");
  122. lcd.setCursor(0,1);
  123. lcd.print("Find HatchDay ");
  124. updatePage();
  125. break;
  126.  
  127. case MANUAL_MTR_TURN:
  128. lcd.setCursor(0,0);
  129. lcd.print("Press Select ");
  130. lcd.setCursor(0,1);
  131. lcd.print("To Turn Motor ");
  132. updatePage();
  133. break;
  134.  
  135. case MOTOR_DEMO:
  136. lcd.setCursor(0,0);
  137. lcd.print("Press Select ");
  138. lcd.setCursor(0,1);
  139. lcd.print("To Run Demo ");
  140. updatePage();
  141. break;
  142.  
  143. case TOGGLE_BUZZER:
  144. lcd.setCursor(0,0);
  145. lcd.print("Press Select ");
  146. lcd.setCursor(0,1);
  147. lcd.print("To toggle ");
  148. updatePage();
  149. break;
  150.  
  151.  
  152. case SHOW_TIME:
  153. lcd.setCursor(0,0);
  154. lcd.print("Press Select ");
  155. lcd.setCursor(0,1);
  156. lcd.print("To Show Time ");
  157. updatePage();
  158. break;
  159.  
  160. }
  161. }
  162.  
  163.  
  164.  
  165. void updateBuzzer(){
  166. }
  167.  
  168. void countDownForHatch(){
  169. }
Add Comment
Please, Sign In to add comment