Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. #include <Wire.h>
  3. #include "RTClib.h"
  4.  
  5. SoftwareSerial bluetooth(0, 1);
  6.  
  7. char charr;
  8.  
  9. RTC_DS1307 rtc;
  10.  
  11. void setup() {
  12. // put your setup code here, to run once:
  13. pinMode(8, OUTPUT);
  14. bluetooth.begin(9600);
  15. digitalWrite(8, HIGH);
  16.  
  17. Serial.begin(9600);
  18. if (! rtc.begin()) {
  19. Serial.println("Couldn't find RTC");
  20. while (1);
  21. }
  22.  
  23. if (! rtc.isrunning()) {
  24. Serial.println("RTC is NOT running!");
  25. // following line sets the RTC to the date & time this sketch was compiled
  26. rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  27. // This line sets the RTC with an explicit date & time, for example to set
  28. // January 21, 2014 at 3am you would call:
  29. // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  30. }
  31. }
  32.  
  33.  
  34. boolean startHourDone = false;
  35. boolean startMinutDone = false;
  36. String startHour;
  37. String startMinut;
  38.  
  39. boolean stopHourDone = false;
  40. boolean stopMinutDone = false;
  41. String stopHour;
  42. String stopMinut;
  43.  
  44. void loop() {
  45. // put your main code here, to run repeatedly:
  46.  
  47. DateTime now = rtc.now();
  48.  
  49. /*if(now.minute() == 43){
  50. digitalWrite(8,HIGH);
  51. }*/
  52.  
  53.  
  54. if(bluetooth.available()){
  55. charr = bluetooth.read();
  56. if(startHourDone == false){
  57. if(charr == ':'){
  58. startHourDone = true;
  59. return;
  60. }
  61. startHour += charr;
  62. }else if(startHourDone == true && startMinutDone == false){
  63. if(charr == ':'){
  64. startMinutDone = true;
  65. return;
  66. }
  67. startMinut += charr;
  68. }else if(startHourDone == true && startMinutDone == true && stopHourDone == false){
  69. if(charr == ':'){
  70. stopHourDone = true;
  71. return;
  72. }
  73. stopHour += charr;
  74. }
  75. else if(startHourDone == true && startMinutDone == true && stopHourDone == true && stopMinutDone == false){
  76. if(charr == ':'){
  77. stopMinutDone = true;
  78. return;
  79. }
  80. stopMinut += charr;
  81. }
  82. Serial.println("START : HOUR: " + startHour + " MINUT: " + startMinut);
  83. Serial.println("STOP : HOUR: " + stopHour + " MINUT: " + stopMinut);
  84. }
  85.  
  86. if((String)now.hour() == startHour &&(String) now.minute() == startMinut){
  87. digitalWrite(8, LOW);
  88. Serial.println("OFF!");
  89. }else if ((String)now.hour() == stopHour &&(String) now.minute() == stopMinut){
  90. digitalWrite(8, HIGH);
  91. Serial.println("ON!");
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement