Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. // When a doorbell press gets detected
  2. if (digitalRead(12)==LOW && ((millis()-lastPressed)>60000)){
  3. Serial.println("Pressed!");
  4. // Get date and time
  5. while(!timeClient.update()) {
  6. timeClient.forceUpdate();
  7. }
  8. dayOfWeek = timeClient.getDay();
  9. hourOfDay = timeClient.getHours();
  10. Serial.print("Day of the week: ");
  11. Serial.println(dayOfWeek);
  12. Serial.print("Hour of the day: ");
  13. Serial.println(hourOfDay);
  14. // Check if it's between Mon-Fri and 8am-5pm
  15. if ((dayOfWeek>0 && dayOfWeek<6) && (hourOfDay>7 && hourOfDay<17)){
  16. // An acceptable press has been detected
  17. printed = 0;
  18. display.clearDisplay();
  19. display.setCursor(20,10);
  20. display.println("PRESSED!");
  21. display.display();
  22. delay(1000);
  23. // Send Pushover notification
  24. Serial.println("Sending...");
  25. display.clearDisplay();
  26. display.setCursor(5,10);
  27. display.println("SENDING...");
  28. display.display();
  29. po.send();
  30. Serial.println("Pushover notification sent!");
  31. display.clearDisplay();
  32. display.setCursor(36,10);
  33. display.println("SENT!");
  34. display.display();
  35. delay(500);
  36. display.clearDisplay();
  37. display.display();
  38. delay(250);
  39. display.setCursor(36,10);
  40. display.println("SENT!");
  41. display.display();
  42. delay(500);
  43. display.clearDisplay();
  44. display.display();
  45. delay(250);
  46. display.setCursor(36,10);
  47. display.println("SENT!");
  48. display.display();
  49. delay(500);
  50. display.clearDisplay();
  51. display.display();
  52. delay(250);
  53. display.setCursor(36,10);
  54. display.println("SENT!");
  55. display.display();
  56. }
  57. if((dayOfWeek>0 && dayOfWeek<6) && (hourOfDay==12)){
  58. Serial.println("Lunch notification displayed");
  59. display.clearDisplay();
  60. display.setCursor(18,0);
  61. display.println("GONE FOR");
  62. display.setCursor(36,18);
  63. display.println("LUNCH");
  64. display.display();
  65. }
  66. lastPressed = millis();
  67. timerFinished = 0;
  68. }
  69. // If the button gets pressed while the button cool down is still active
  70. else if (digitalRead(12)==LOW && ((millis()-lastPressed)<60000)){
  71. pressCount++;
  72. Serial.print("Button on cooldown... ");
  73. Serial.print((60000-(millis()-lastPressed))/1000);
  74. Serial.println("s remaining.");
  75. if (pressCount == 1){
  76. display.clearDisplay();
  77. display.setCursor(18,0);
  78. display.println("TRUST ME");
  79. display.setCursor(6,18);
  80. display.println("IT SENT...");
  81. display.display();
  82. }
  83. else if (pressCount == 2){
  84. display.clearDisplay();
  85. display.setCursor(12,10);
  86. display.println("CHILL OUT");
  87. display.display();
  88. }
  89. delay(250);
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement