Advertisement
LshySVK

Ovládanie dverí pre kury

Apr 13th, 2023 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 42.34 KB | Source Code | 0 0
  1. /*
  2.    D3 - Trvalo 5V, (OUTPUT, trvalo HIGH), napajanie pre pull-up rezistory pre endstopy
  3.    D4 - ovladanie H mostiku strana A (OUTPUT)
  4.     D5 - ovladanie H mostiku strana B (OUTPUT)
  5.     D6 - Endstop 1 (INPUT)
  6.     D7 - Endstop 2 (INPUT)
  7.     D8 - S1 (INPUT_PULLUP)
  8.     D9 - S2 (INPUT_PULLUP)
  9.     D10 - NC
  10.     D11 - JP2 (INPUT_PULLUP)
  11.     D12 - JP1 (INPUT_PULLUP)
  12. */
  13.  
  14.  
  15.  
  16. #include <DS3231.h>
  17.  
  18. #define HbridgeA 4
  19. #define HbridgeB 5
  20. #define EndstopOpened 6
  21. #define EndstopClosed 7
  22. #define Button1 8
  23. #define Button2 9
  24. #define Jumper1 12
  25. #define Jumper2 11
  26.  
  27. DS3231  rtc(SDA, SCL);
  28. Time  t;
  29.  
  30.  
  31. boolean dayState = 1;   //Stav dna (den-1 / noc-0)
  32.  
  33.  
  34.  
  35. void Hbridge(short state) {
  36.   switch (state) {
  37.     case 1:                                         //Otvaranie dveri
  38.       digitalWrite(HbridgeB, LOW);
  39.       delayMicroseconds(10);
  40.       for (int i = 1; i < 1000; i++) {              //Softstart funkcia
  41.         digitalWrite(HbridgeA, LOW);
  42.         delayMicroseconds(1000 - i);
  43.         digitalWrite(HbridgeA, HIGH);
  44.         delayMicroseconds(i);
  45.       }
  46.       break;
  47.     case 2:                                       //Zatvaranie dveri
  48.       digitalWrite(HbridgeA, LOW);
  49.       delayMicroseconds(10);
  50.       for (int i = 1; i < 1000; i++) {            //Softstart funkcia
  51.         digitalWrite(HbridgeB, LOW);
  52.         delayMicroseconds(1000 - i);
  53.         digitalWrite(HbridgeB, HIGH);
  54.         delayMicroseconds(i);
  55.       }
  56.       break;
  57.     default:                                      //Vypnutie motoru
  58.       digitalWrite(HbridgeA, LOW);
  59.       digitalWrite(HbridgeB, LOW);
  60.       break;
  61.   }
  62. }
  63.  
  64.  
  65.  
  66.  
  67. void updateDayState() {                                  //Funkcia pre zistenie ci je svetlo alebo nie
  68.   t = rtc.getTime();                                     //Ziska aktualny cas z RTC modulu
  69.   int currentMin = ((t.hour * 60) + t.min);
  70.   int currentDay = (t.date);
  71.   String currentMonthStr = rtc.getMonthStr();
  72.   int currentMonth;
  73.  
  74.   if (currentMonthStr == "January") currentMonth = 1;         //Premeni nazvy mesiacov na cisla
  75.   else if (currentMonthStr == "February") currentMonth = 2;
  76.   else if (currentMonthStr == "March") currentMonth = 3;
  77.   else if (currentMonthStr == "April") currentMonth = 4;
  78.   else if (currentMonthStr == "May") currentMonth = 5;
  79.   else if (currentMonthStr == "June") currentMonth = 6;
  80.   else if (currentMonthStr == "July") currentMonth = 7;
  81.   else if (currentMonthStr == "August") currentMonth = 8;
  82.   else if (currentMonthStr == "September") currentMonth = 9;
  83.   else if (currentMonthStr == "October") currentMonth = 10;
  84.   else if (currentMonthStr == "November") currentMonth = 11;
  85.   else if (currentMonthStr == "December") currentMonth = 12;
  86.  
  87.   switch (currentMonth) {
  88.     case 1:                                                                                         //Január
  89.       if ((currentDay == 1) && (currentMin >= 461) && (currentMin <= 996)) dayState = 1;
  90.       else if ((currentDay == 2) && (currentMin >= 461) && (currentMin <= 997)) dayState = 1;
  91.       else if ((currentDay == 3) && (currentMin >= 461) && (currentMin <= 998)) dayState = 1;
  92.       else if ((currentDay == 4) && (currentMin >= 461) && (currentMin <= 999)) dayState = 1;
  93.       else if ((currentDay == 5) && (currentMin >= 460) && (currentMin <= 1000)) dayState = 1;
  94.       else if ((currentDay == 6) && (currentMin >= 460) && (currentMin <= 1001)) dayState = 1;
  95.       else if ((currentDay == 7) && (currentMin >= 460) && (currentMin <= 1002)) dayState = 1;
  96.       else if ((currentDay == 8) && (currentMin >= 460) && (currentMin <= 1003)) dayState = 1;
  97.       else if ((currentDay == 9) && (currentMin >= 459) && (currentMin <= 1004)) dayState = 1;
  98.       else if ((currentDay == 10) && (currentMin >= 459) && (currentMin <= 1005)) dayState = 1;
  99.       else if ((currentDay == 11) && (currentMin >= 458) && (currentMin <= 1006)) dayState = 1;
  100.       else if ((currentDay == 12) && (currentMin >= 458) && (currentMin <= 1008)) dayState = 1;
  101.       else if ((currentDay == 13) && (currentMin >= 457) && (currentMin <= 1009)) dayState = 1;
  102.       else if ((currentDay == 14) && (currentMin >= 456) && (currentMin <= 1010)) dayState = 1;
  103.       else if ((currentDay == 15) && (currentMin >= 456) && (currentMin <= 1012)) dayState = 1;
  104.       else if ((currentDay == 16) && (currentMin >= 455) && (currentMin <= 1013)) dayState = 1;
  105.       else if ((currentDay == 17) && (currentMin >= 454) && (currentMin <= 1014)) dayState = 1;
  106.       else if ((currentDay == 18) && (currentMin >= 454) && (currentMin <= 1016)) dayState = 1;
  107.       else if ((currentDay == 19) && (currentMin >= 453) && (currentMin <= 1017)) dayState = 1;
  108.       else if ((currentDay == 20) && (currentMin >= 452) && (currentMin <= 1018)) dayState = 1;
  109.       else if ((currentDay == 21) && (currentMin >= 451) && (currentMin <= 1020)) dayState = 1;
  110.       else if ((currentDay == 22) && (currentMin >= 450) && (currentMin <= 1021)) dayState = 1;
  111.       else if ((currentDay == 23) && (currentMin >= 449) && (currentMin <= 1023)) dayState = 1;
  112.       else if ((currentDay == 24) && (currentMin >= 448) && (currentMin <= 1024)) dayState = 1;
  113.       else if ((currentDay == 25) && (currentMin >= 447) && (currentMin <= 1026)) dayState = 1;
  114.       else if ((currentDay == 26) && (currentMin >= 446) && (currentMin <= 1027)) dayState = 1;
  115.       else if ((currentDay == 27) && (currentMin >= 444) && (currentMin <= 1029)) dayState = 1;
  116.       else if ((currentDay == 28) && (currentMin >= 443) && (currentMin <= 1030)) dayState = 1;
  117.       else if ((currentDay == 29) && (currentMin >= 442) && (currentMin <= 1032)) dayState = 1;
  118.       else if ((currentDay == 30) && (currentMin >= 441) && (currentMin <= 1033)) dayState = 1;
  119.       else if ((currentDay == 31) && (currentMin >= 439) && (currentMin <= 1035)) dayState = 1;
  120.       else dayState = 0;
  121.       break;
  122.     case 2:                                                                                           //Február
  123.       if ((currentDay == 1) && (currentMin >= 438) && (currentMin <= 1036)) dayState = 1;
  124.       else if ((currentDay == 2) && (currentMin >= 437) && (currentMin <= 1038)) dayState = 1;
  125.       else if ((currentDay == 3) && (currentMin >= 435) && (currentMin <= 1039)) dayState = 1;
  126.       else if ((currentDay == 4) && (currentMin >= 434) && (currentMin <= 1041)) dayState = 1;
  127.       else if ((currentDay == 5) && (currentMin >= 432) && (currentMin <= 1042)) dayState = 1;
  128.       else if ((currentDay == 6) && (currentMin >= 431) && (currentMin <= 1044)) dayState = 1;
  129.       else if ((currentDay == 7) && (currentMin >= 429) && (currentMin <= 1046)) dayState = 1;
  130.       else if ((currentDay == 8) && (currentMin >= 428) && (currentMin <= 1047)) dayState = 1;
  131.       else if ((currentDay == 9) && (currentMin >= 426) && (currentMin <= 1049)) dayState = 1;
  132.       else if ((currentDay == 10) && (currentMin >= 424) && (currentMin <= 1050)) dayState = 1;
  133.       else if ((currentDay == 11) && (currentMin >= 423) && (currentMin <= 1052)) dayState = 1;
  134.       else if ((currentDay == 12) && (currentMin >= 421) && (currentMin <= 1053)) dayState = 1;
  135.       else if ((currentDay == 13) && (currentMin >= 420) && (currentMin <= 1055)) dayState = 1;
  136.       else if ((currentDay == 14) && (currentMin >= 418) && (currentMin <= 1057)) dayState = 1;
  137.       else if ((currentDay == 15) && (currentMin >= 416) && (currentMin <= 1058)) dayState = 1;
  138.       else if ((currentDay == 16) && (currentMin >= 414) && (currentMin <= 1060)) dayState = 1;
  139.       else if ((currentDay == 17) && (currentMin >= 413) && (currentMin <= 1061)) dayState = 1;
  140.       else if ((currentDay == 18) && (currentMin >= 411) && (currentMin <= 1063)) dayState = 1;
  141.       else if ((currentDay == 19) && (currentMin >= 409) && (currentMin <= 1064)) dayState = 1;
  142.       else if ((currentDay == 20) && (currentMin >= 407) && (currentMin <= 1066)) dayState = 1;
  143.       else if ((currentDay == 21) && (currentMin >= 405) && (currentMin <= 1068)) dayState = 1;
  144.       else if ((currentDay == 22) && (currentMin >= 403) && (currentMin <= 1069)) dayState = 1;
  145.       else if ((currentDay == 23) && (currentMin >= 401) && (currentMin <= 1071)) dayState = 1;
  146.       else if ((currentDay == 24) && (currentMin >= 400) && (currentMin <= 1072)) dayState = 1;
  147.       else if ((currentDay == 25) && (currentMin >= 398) && (currentMin <= 1074)) dayState = 1;
  148.       else if ((currentDay == 26) && (currentMin >= 396) && (currentMin <= 1076)) dayState = 1;
  149.       else if ((currentDay == 27) && (currentMin >= 394) && (currentMin <= 1077)) dayState = 1;
  150.       else if ((currentDay == 28) && (currentMin >= 392) && (currentMin <= 1079)) dayState = 1;
  151.       else if ((currentDay == 29) && (currentMin >= 390) && (currentMin <= 1080)) dayState = 1;
  152.       else dayState = 0;
  153.       break;
  154.     case 3:                                                                                      //Marec
  155.       if ((currentDay == 1) && (currentMin >= 388) && (currentMin <= 1082)) dayState = 1;
  156.       else if ((currentDay == 2) && (currentMin >= 386) && (currentMin <= 1083)) dayState = 1;
  157.       else if ((currentDay == 3) && (currentMin >= 384) && (currentMin <= 1085)) dayState = 1;
  158.       else if ((currentDay == 4) && (currentMin >= 382) && (currentMin <= 1086)) dayState = 1;
  159.       else if ((currentDay == 5) && (currentMin >= 380) && (currentMin <= 1088)) dayState = 1;
  160.       else if ((currentDay == 6) && (currentMin >= 378) && (currentMin <= 1090)) dayState = 1;
  161.       else if ((currentDay == 7) && (currentMin >= 376) && (currentMin <= 1091)) dayState = 1;
  162.       else if ((currentDay == 8) && (currentMin >= 374) && (currentMin <= 1093)) dayState = 1;
  163.       else if ((currentDay == 9) && (currentMin >= 372) && (currentMin <= 1094)) dayState = 1;
  164.       else if ((currentDay == 10) && (currentMin >= 369) && (currentMin <= 1096)) dayState = 1;
  165.       else if ((currentDay == 11) && (currentMin >= 367) && (currentMin <= 1097)) dayState = 1;
  166.       else if ((currentDay == 12) && (currentMin >= 365) && (currentMin <= 1099)) dayState = 1;
  167.       else if ((currentDay == 13) && (currentMin >= 363) && (currentMin <= 1100)) dayState = 1;
  168.       else if ((currentDay == 14) && (currentMin >= 361) && (currentMin <= 1102)) dayState = 1;
  169.       else if ((currentDay == 15) && (currentMin >= 359) && (currentMin <= 1104)) dayState = 1;
  170.       else if ((currentDay == 16) && (currentMin >= 357) && (currentMin <= 1105)) dayState = 1;
  171.       else if ((currentDay == 17) && (currentMin >= 355) && (currentMin <= 1107)) dayState = 1;
  172.       else if ((currentDay == 18) && (currentMin >= 353) && (currentMin <= 1108)) dayState = 1;
  173.       else if ((currentDay == 19) && (currentMin >= 351) && (currentMin <= 1110)) dayState = 1;
  174.       else if ((currentDay == 20) && (currentMin >= 348) && (currentMin <= 1111)) dayState = 1;
  175.       else if ((currentDay == 21) && (currentMin >= 346) && (currentMin <= 1113)) dayState = 1;
  176.       else if ((currentDay == 22) && (currentMin >= 344) && (currentMin <= 1114)) dayState = 1;
  177.       else if ((currentDay == 23) && (currentMin >= 342) && (currentMin <= 1116)) dayState = 1;
  178.       else if ((currentDay == 24) && (currentMin >= 340) && (currentMin <= 1118)) dayState = 1;
  179.       else if ((currentDay == 25) && (currentMin >= 338) && (currentMin <= 1119)) dayState = 1;
  180.       else if ((currentDay == 26) && (currentMin >= 336) && (currentMin <= 1121)) dayState = 1;
  181.       else if ((currentDay == 27) && (currentMin >= 334) && (currentMin <= 1122)) dayState = 1;
  182.       else if ((currentDay == 28) && (currentMin >= 332) && (currentMin <= 1124)) dayState = 1;
  183.       else if ((currentDay == 29) && (currentMin >= 329) && (currentMin <= 1125)) dayState = 1;
  184.       else if ((currentDay == 30) && (currentMin >= 327) && (currentMin <= 1127)) dayState = 1;
  185.       else if ((currentDay == 31) && (currentMin >= 325) && (currentMin <= 1129)) dayState = 1;
  186.       else dayState = 0;
  187.       break;
  188.     case 4:                                                                                        //Apríl
  189.       if ((currentDay == 1) && (currentMin >= 323) && (currentMin <= 1130)) dayState = 1;
  190.       else if ((currentDay == 2) && (currentMin >= 321) && (currentMin <= 1132)) dayState = 1;
  191.       else if ((currentDay == 3) && (currentMin >= 319) && (currentMin <= 1133)) dayState = 1;
  192.       else if ((currentDay == 4) && (currentMin >= 317) && (currentMin <= 1135)) dayState = 1;
  193.       else if ((currentDay == 5) && (currentMin >= 315) && (currentMin <= 1136)) dayState = 1;
  194.       else if ((currentDay == 6) && (currentMin >= 313) && (currentMin <= 1138)) dayState = 1;
  195.       else if ((currentDay == 7) && (currentMin >= 311) && (currentMin <= 1140)) dayState = 1;
  196.       else if ((currentDay == 8) && (currentMin >= 309) && (currentMin <= 1141)) dayState = 1;
  197.       else if ((currentDay == 9) && (currentMin >= 306) && (currentMin <= 1143)) dayState = 1;
  198.       else if ((currentDay == 10) && (currentMin >= 304) && (currentMin <= 1144)) dayState = 1;
  199.       else if ((currentDay == 11) && (currentMin >= 302) && (currentMin <= 1146)) dayState = 1;
  200.       else if ((currentDay == 12) && (currentMin >= 300) && (currentMin <= 1148)) dayState = 1;
  201.       else if ((currentDay == 13) && (currentMin >= 298) && (currentMin <= 1149)) dayState = 1;
  202.       else if ((currentDay == 14) && (currentMin >= 296) && (currentMin <= 1151)) dayState = 1;
  203.       else if ((currentDay == 15) && (currentMin >= 294) && (currentMin <= 1153)) dayState = 1;
  204.       else if ((currentDay == 16) && (currentMin >= 292) && (currentMin <= 1154)) dayState = 1;
  205.       else if ((currentDay == 17) && (currentMin >= 290) && (currentMin <= 1156)) dayState = 1;
  206.       else if ((currentDay == 18) && (currentMin >= 288) && (currentMin <= 1157)) dayState = 1;
  207.       else if ((currentDay == 19) && (currentMin >= 287) && (currentMin <= 1159)) dayState = 1;
  208.       else if ((currentDay == 20) && (currentMin >= 285) && (currentMin <= 1161)) dayState = 1;
  209.       else if ((currentDay == 21) && (currentMin >= 283) && (currentMin <= 1162)) dayState = 1;
  210.       else if ((currentDay == 22) && (currentMin >= 281) && (currentMin <= 1164)) dayState = 1;
  211.       else if ((currentDay == 23) && (currentMin >= 279) && (currentMin <= 1166)) dayState = 1;
  212.       else if ((currentDay == 24) && (currentMin >= 277) && (currentMin <= 1167)) dayState = 1;
  213.       else if ((currentDay == 25) && (currentMin >= 275) && (currentMin <= 1169)) dayState = 1;
  214.       else if ((currentDay == 26) && (currentMin >= 273) && (currentMin <= 1171)) dayState = 1;
  215.       else if ((currentDay == 27) && (currentMin >= 272) && (currentMin <= 1172)) dayState = 1;
  216.       else if ((currentDay == 28) && (currentMin >= 270) && (currentMin <= 1174)) dayState = 1;
  217.       else if ((currentDay == 29) && (currentMin >= 268) && (currentMin <= 1176)) dayState = 1;
  218.       else if ((currentDay == 30) && (currentMin >= 266) && (currentMin <= 1177)) dayState = 1;
  219.       else dayState = 0;
  220.       break;
  221.     case 5:                                                                                         //Máj
  222.       if ((currentDay == 1) && (currentMin >= 265) && (currentMin <= 1179)) dayState = 1;
  223.       else if ((currentDay == 2) && (currentMin >= 263) && (currentMin <= 1181)) dayState = 1;
  224.       else if ((currentDay == 3) && (currentMin >= 261) && (currentMin <= 1182)) dayState = 1;
  225.       else if ((currentDay == 4) && (currentMin >= 260) && (currentMin <= 1184)) dayState = 1;
  226.       else if ((currentDay == 5) && (currentMin >= 258) && (currentMin <= 1185)) dayState = 1;
  227.       else if ((currentDay == 6) && (currentMin >= 256) && (currentMin <= 1187)) dayState = 1;
  228.       else if ((currentDay == 7) && (currentMin >= 255) && (currentMin <= 1189)) dayState = 1;
  229.       else if ((currentDay == 8) && (currentMin >= 253) && (currentMin <= 1190)) dayState = 1;
  230.       else if ((currentDay == 9) && (currentMin >= 252) && (currentMin <= 1192)) dayState = 1;
  231.       else if ((currentDay == 10) && (currentMin >= 250) && (currentMin <= 1194)) dayState = 1;
  232.       else if ((currentDay == 11) && (currentMin >= 249) && (currentMin <= 1195)) dayState = 1;
  233.       else if ((currentDay == 12) && (currentMin >= 247) && (currentMin <= 1197)) dayState = 1;
  234.       else if ((currentDay == 13) && (currentMin >= 246) && (currentMin <= 1198)) dayState = 1;
  235.       else if ((currentDay == 14) && (currentMin >= 245) && (currentMin <= 1200)) dayState = 1;
  236.       else if ((currentDay == 15) && (currentMin >= 243) && (currentMin <= 1201)) dayState = 1;
  237.       else if ((currentDay == 16) && (currentMin >= 242) && (currentMin <= 1203)) dayState = 1;
  238.       else if ((currentDay == 17) && (currentMin >= 241) && (currentMin <= 1204)) dayState = 1;
  239.       else if ((currentDay == 18) && (currentMin >= 239) && (currentMin <= 1206)) dayState = 1;
  240.       else if ((currentDay == 19) && (currentMin >= 238) && (currentMin <= 1207)) dayState = 1;
  241.       else if ((currentDay == 20) && (currentMin >= 237) && (currentMin <= 1209)) dayState = 1;
  242.       else if ((currentDay == 21) && (currentMin >= 236) && (currentMin <= 1210)) dayState = 1;
  243.       else if ((currentDay == 22) && (currentMin >= 235) && (currentMin <= 1212)) dayState = 1;
  244.       else if ((currentDay == 23) && (currentMin >= 234) && (currentMin <= 1213)) dayState = 1;
  245.       else if ((currentDay == 24) && (currentMin >= 233) && (currentMin <= 1214)) dayState = 1;
  246.       else if ((currentDay == 25) && (currentMin >= 232) && (currentMin <= 1216)) dayState = 1;
  247.       else if ((currentDay == 26) && (currentMin >= 231) && (currentMin <= 1217)) dayState = 1;
  248.       else if ((currentDay == 27) && (currentMin >= 230) && (currentMin <= 1218)) dayState = 1;
  249.       else if ((currentDay == 28) && (currentMin >= 229) && (currentMin <= 1220)) dayState = 1;
  250.       else if ((currentDay == 29) && (currentMin >= 228) && (currentMin <= 1221)) dayState = 1;
  251.       else if ((currentDay == 30) && (currentMin >= 227) && (currentMin <= 1222)) dayState = 1;
  252.       else if ((currentDay == 31) && (currentMin >= 227) && (currentMin <= 1223)) dayState = 1;
  253.       else dayState = 0;
  254.       break;
  255.     case 6:                                                                                       //Jún
  256.       if ((currentDay == 1) && (currentMin >= 226) && (currentMin <= 1224)) dayState = 1;
  257.       else if ((currentDay == 2) && (currentMin >= 225) && (currentMin <= 1226)) dayState = 1;
  258.       else if ((currentDay == 3) && (currentMin >= 225) && (currentMin <= 1227)) dayState = 1;
  259.       else if ((currentDay == 4) && (currentMin >= 224) && (currentMin <= 1228)) dayState = 1;
  260.       else if ((currentDay == 5) && (currentMin >= 224) && (currentMin <= 1229)) dayState = 1;
  261.       else if ((currentDay == 6) && (currentMin >= 223) && (currentMin <= 1230)) dayState = 1;
  262.       else if ((currentDay == 7) && (currentMin >= 223) && (currentMin <= 1230)) dayState = 1;
  263.       else if ((currentDay == 8) && (currentMin >= 222) && (currentMin <= 1231)) dayState = 1;
  264.       else if ((currentDay == 9) && (currentMin >= 222) && (currentMin <= 1232)) dayState = 1;
  265.       else if ((currentDay == 10) && (currentMin >= 222) && (currentMin <= 1233)) dayState = 1;
  266.       else if ((currentDay == 11) && (currentMin >= 221) && (currentMin <= 1234)) dayState = 1;
  267.       else if ((currentDay == 12) && (currentMin >= 221) && (currentMin <= 1234)) dayState = 1;
  268.       else if ((currentDay == 13) && (currentMin >= 221) && (currentMin <= 1235)) dayState = 1;
  269.       else if ((currentDay == 14) && (currentMin >= 221) && (currentMin <= 1235)) dayState = 1;
  270.       else if ((currentDay == 15) && (currentMin >= 221) && (currentMin <= 1236)) dayState = 1;
  271.       else if ((currentDay == 16) && (currentMin >= 221) && (currentMin <= 1236)) dayState = 1;
  272.       else if ((currentDay == 17) && (currentMin >= 221) && (currentMin <= 1237)) dayState = 1;
  273.       else if ((currentDay == 18) && (currentMin >= 221) && (currentMin <= 1237)) dayState = 1;
  274.       else if ((currentDay == 19) && (currentMin >= 221) && (currentMin <= 1238)) dayState = 1;
  275.       else if ((currentDay == 20) && (currentMin >= 221) && (currentMin <= 1238)) dayState = 1;
  276.       else if ((currentDay == 21) && (currentMin >= 221) && (currentMin <= 1238)) dayState = 1;
  277.       else if ((currentDay == 22) && (currentMin >= 222) && (currentMin <= 1238)) dayState = 1;
  278.       else if ((currentDay == 23) && (currentMin >= 222) && (currentMin <= 1238)) dayState = 1;
  279.       else if ((currentDay == 24) && (currentMin >= 222) && (currentMin <= 1238)) dayState = 1;
  280.       else if ((currentDay == 25) && (currentMin >= 223) && (currentMin <= 1238)) dayState = 1;
  281.       else if ((currentDay == 26) && (currentMin >= 223) && (currentMin <= 1238)) dayState = 1;
  282.       else if ((currentDay == 27) && (currentMin >= 224) && (currentMin <= 1238)) dayState = 1;
  283.       else if ((currentDay == 28) && (currentMin >= 224) && (currentMin <= 1238)) dayState = 1;
  284.       else if ((currentDay == 29) && (currentMin >= 225) && (currentMin <= 1238)) dayState = 1;
  285.       else if ((currentDay == 30) && (currentMin >= 225) && (currentMin <= 1237)) dayState = 1;
  286.       else dayState = 0;
  287.       break;
  288.     case 7:                                                                                         //Júl
  289.       if ((currentDay == 1) && (currentMin >= 226) && (currentMin <= 1237)) dayState = 1;
  290.       else if ((currentDay == 2) && (currentMin >= 226) && (currentMin <= 1236)) dayState = 1;
  291.       else if ((currentDay == 3) && (currentMin >= 227) && (currentMin <= 1236)) dayState = 1;
  292.       else if ((currentDay == 4) && (currentMin >= 228) && (currentMin <= 1235)) dayState = 1;
  293.       else if ((currentDay == 5) && (currentMin >= 229) && (currentMin <= 1235)) dayState = 1;
  294.       else if ((currentDay == 6) && (currentMin >= 229) && (currentMin <= 1234)) dayState = 1;
  295.       else if ((currentDay == 7) && (currentMin >= 230) && (currentMin <= 1234)) dayState = 1;
  296.       else if ((currentDay == 8) && (currentMin >= 231) && (currentMin <= 1233)) dayState = 1;
  297.       else if ((currentDay == 9) && (currentMin >= 232) && (currentMin <= 1232)) dayState = 1;
  298.       else if ((currentDay == 10) && (currentMin >= 233) && (currentMin <= 1231)) dayState = 1;
  299.       else if ((currentDay == 11) && (currentMin >= 234) && (currentMin <= 1230)) dayState = 1;
  300.       else if ((currentDay == 12) && (currentMin >= 235) && (currentMin <= 1229)) dayState = 1;
  301.       else if ((currentDay == 13) && (currentMin >= 236) && (currentMin <= 1228)) dayState = 1;
  302.       else if ((currentDay == 14) && (currentMin >= 237) && (currentMin <= 1227)) dayState = 1;
  303.       else if ((currentDay == 15) && (currentMin >= 238) && (currentMin <= 1226)) dayState = 1;
  304.       else if ((currentDay == 16) && (currentMin >= 239) && (currentMin <= 1225)) dayState = 1;
  305.       else if ((currentDay == 17) && (currentMin >= 240) && (currentMin <= 1224)) dayState = 1;
  306.       else if ((currentDay == 18) && (currentMin >= 241) && (currentMin <= 1223)) dayState = 1;
  307.       else if ((currentDay == 19) && (currentMin >= 243) && (currentMin <= 1222)) dayState = 1;
  308.       else if ((currentDay == 20) && (currentMin >= 244) && (currentMin <= 1220)) dayState = 1;
  309.       else if ((currentDay == 21) && (currentMin >= 245) && (currentMin <= 1219)) dayState = 1;
  310.       else if ((currentDay == 22) && (currentMin >= 246) && (currentMin <= 1218)) dayState = 1;
  311.       else if ((currentDay == 23) && (currentMin >= 247) && (currentMin <= 1216)) dayState = 1;
  312.       else if ((currentDay == 24) && (currentMin >= 249) && (currentMin <= 1215)) dayState = 1;
  313.       else if ((currentDay == 25) && (currentMin >= 250) && (currentMin <= 1214)) dayState = 1;
  314.       else if ((currentDay == 26) && (currentMin >= 251) && (currentMin <= 1212)) dayState = 1;
  315.       else if ((currentDay == 27) && (currentMin >= 252) && (currentMin <= 1211)) dayState = 1;
  316.       else if ((currentDay == 28) && (currentMin >= 254) && (currentMin <= 1209)) dayState = 1;
  317.       else if ((currentDay == 29) && (currentMin >= 255) && (currentMin <= 1207)) dayState = 1;
  318.       else if ((currentDay == 30) && (currentMin >= 256) && (currentMin <= 1206)) dayState = 1;
  319.       else if ((currentDay == 31) && (currentMin >= 258) && (currentMin <= 1204)) dayState = 1;
  320.       else dayState = 0;
  321.       break;
  322.     case 8:                                                                                       //August
  323.       if ((currentDay == 1) && (currentMin >= 259) && (currentMin <= 1203)) dayState = 1;
  324.       else if ((currentDay == 2) && (currentMin >= 260) && (currentMin <= 1201)) dayState = 1;
  325.       else if ((currentDay == 3) && (currentMin >= 262) && (currentMin <= 1199)) dayState = 1;
  326.       else if ((currentDay == 4) && (currentMin >= 263) && (currentMin <= 1197)) dayState = 1;
  327.       else if ((currentDay == 5) && (currentMin >= 265) && (currentMin <= 1196)) dayState = 1;
  328.       else if ((currentDay == 6) && (currentMin >= 266) && (currentMin <= 1194)) dayState = 1;
  329.       else if ((currentDay == 7) && (currentMin >= 267) && (currentMin <= 1192)) dayState = 1;
  330.       else if ((currentDay == 8) && (currentMin >= 269) && (currentMin <= 1190)) dayState = 1;
  331.       else if ((currentDay == 9) && (currentMin >= 270) && (currentMin <= 1188)) dayState = 1;
  332.       else if ((currentDay == 10) && (currentMin >= 272) && (currentMin <= 1186)) dayState = 1;
  333.       else if ((currentDay == 11) && (currentMin >= 273) && (currentMin <= 1184)) dayState = 1;
  334.       else if ((currentDay == 12) && (currentMin >= 274) && (currentMin <= 1183)) dayState = 1;
  335.       else if ((currentDay == 13) && (currentMin >= 276) && (currentMin <= 1181)) dayState = 1;
  336.       else if ((currentDay == 14) && (currentMin >= 277) && (currentMin <= 1179)) dayState = 1;
  337.       else if ((currentDay == 15) && (currentMin >= 279) && (currentMin <= 1177)) dayState = 1;
  338.       else if ((currentDay == 16) && (currentMin >= 280) && (currentMin <= 1175)) dayState = 1;
  339.       else if ((currentDay == 17) && (currentMin >= 282) && (currentMin <= 1173)) dayState = 1;
  340.       else if ((currentDay == 18) && (currentMin >= 283) && (currentMin <= 1171)) dayState = 1;
  341.       else if ((currentDay == 19) && (currentMin >= 284) && (currentMin <= 1169)) dayState = 1;
  342.       else if ((currentDay == 20) && (currentMin >= 286) && (currentMin <= 1167)) dayState = 1;
  343.       else if ((currentDay == 21) && (currentMin >= 287) && (currentMin <= 1164)) dayState = 1;
  344.       else if ((currentDay == 22) && (currentMin >= 289) && (currentMin <= 1162)) dayState = 1;
  345.       else if ((currentDay == 23) && (currentMin >= 290) && (currentMin <= 1160)) dayState = 1;
  346.       else if ((currentDay == 24) && (currentMin >= 292) && (currentMin <= 1158)) dayState = 1;
  347.       else if ((currentDay == 25) && (currentMin >= 293) && (currentMin <= 1156)) dayState = 1;
  348.       else if ((currentDay == 26) && (currentMin >= 294) && (currentMin <= 1154)) dayState = 1;
  349.       else if ((currentDay == 27) && (currentMin >= 296) && (currentMin <= 1152)) dayState = 1;
  350.       else if ((currentDay == 28) && (currentMin >= 297) && (currentMin <= 1150)) dayState = 1;
  351.       else if ((currentDay == 29) && (currentMin >= 299) && (currentMin <= 1148)) dayState = 1;
  352.       else if ((currentDay == 30) && (currentMin >= 300) && (currentMin <= 1145)) dayState = 1;
  353.       else if ((currentDay == 31) && (currentMin >= 302) && (currentMin <= 1143)) dayState = 1;
  354.       else dayState = 0;
  355.       break;
  356.     case 9:                                                                                      //September
  357.       if ((currentDay == 1) && (currentMin >= 303) && (currentMin <= 1141)) dayState = 1;
  358.       else if ((currentDay == 2) && (currentMin >= 304) && (currentMin <= 1139)) dayState = 1;
  359.       else if ((currentDay == 3) && (currentMin >= 306) && (currentMin <= 1137)) dayState = 1;
  360.       else if ((currentDay == 4) && (currentMin >= 307) && (currentMin <= 1135)) dayState = 1;
  361.       else if ((currentDay == 5) && (currentMin >= 309) && (currentMin <= 1132)) dayState = 1;
  362.       else if ((currentDay == 6) && (currentMin >= 310) && (currentMin <= 1130)) dayState = 1;
  363.       else if ((currentDay == 7) && (currentMin >= 312) && (currentMin <= 1128)) dayState = 1;
  364.       else if ((currentDay == 8) && (currentMin >= 313) && (currentMin <= 1126)) dayState = 1;
  365.       else if ((currentDay == 9) && (currentMin >= 314) && (currentMin <= 1124)) dayState = 1;
  366.       else if ((currentDay == 10) && (currentMin >= 316) && (currentMin <= 1121)) dayState = 1;
  367.       else if ((currentDay == 11) && (currentMin >= 317) && (currentMin <= 1119)) dayState = 1;
  368.       else if ((currentDay == 12) && (currentMin >= 319) && (currentMin <= 1117)) dayState = 1;
  369.       else if ((currentDay == 13) && (currentMin >= 320) && (currentMin <= 1115)) dayState = 1;
  370.       else if ((currentDay == 14) && (currentMin >= 322) && (currentMin <= 1113)) dayState = 1;
  371.       else if ((currentDay == 15) && (currentMin >= 323) && (currentMin <= 1110)) dayState = 1;
  372.       else if ((currentDay == 16) && (currentMin >= 324) && (currentMin <= 1108)) dayState = 1;
  373.       else if ((currentDay == 17) && (currentMin >= 326) && (currentMin <= 1106)) dayState = 1;
  374.       else if ((currentDay == 18) && (currentMin >= 327) && (currentMin <= 1104)) dayState = 1;
  375.       else if ((currentDay == 19) && (currentMin >= 329) && (currentMin <= 1102)) dayState = 1;
  376.       else if ((currentDay == 20) && (currentMin >= 330) && (currentMin <= 1099)) dayState = 1;
  377.       else if ((currentDay == 21) && (currentMin >= 332) && (currentMin <= 1097)) dayState = 1;
  378.       else if ((currentDay == 22) && (currentMin >= 333) && (currentMin <= 1095)) dayState = 1;
  379.       else if ((currentDay == 23) && (currentMin >= 335) && (currentMin <= 1093)) dayState = 1;
  380.       else if ((currentDay == 24) && (currentMin >= 336) && (currentMin <= 1091)) dayState = 1;
  381.       else if ((currentDay == 25) && (currentMin >= 337) && (currentMin <= 1089)) dayState = 1;
  382.       else if ((currentDay == 26) && (currentMin >= 339) && (currentMin <= 1087)) dayState = 1;
  383.       else if ((currentDay == 27) && (currentMin >= 340) && (currentMin <= 1084)) dayState = 1;
  384.       else if ((currentDay == 28) && (currentMin >= 342) && (currentMin <= 1082)) dayState = 1;
  385.       else if ((currentDay == 29) && (currentMin >= 343) && (currentMin <= 1080)) dayState = 1;
  386.       else if ((currentDay == 30) && (currentMin >= 345) && (currentMin <= 1078)) dayState = 1;
  387.       else dayState = 0;
  388.       break;
  389.     case 10:                                                                                   //Október
  390.       if ((currentDay == 1) && (currentMin >= 346) && (currentMin <= 1076)) dayState = 1;
  391.       else if ((currentDay == 2) && (currentMin >= 348) && (currentMin <= 1074)) dayState = 1;
  392.       else if ((currentDay == 3) && (currentMin >= 349) && (currentMin <= 1072)) dayState = 1;
  393.       else if ((currentDay == 4) && (currentMin >= 351) && (currentMin <= 1070)) dayState = 1;
  394.       else if ((currentDay == 5) && (currentMin >= 352) && (currentMin <= 1068)) dayState = 1;
  395.       else if ((currentDay == 6) && (currentMin >= 354) && (currentMin <= 1066)) dayState = 1;
  396.       else if ((currentDay == 7) && (currentMin >= 355) && (currentMin <= 1063)) dayState = 1;
  397.       else if ((currentDay == 8) && (currentMin >= 357) && (currentMin <= 1061)) dayState = 1;
  398.       else if ((currentDay == 9) && (currentMin >= 358) && (currentMin <= 1059)) dayState = 1;
  399.       else if ((currentDay == 10) && (currentMin >= 360) && (currentMin <= 1057)) dayState = 1;
  400.       else if ((currentDay == 11) && (currentMin >= 361) && (currentMin <= 1055)) dayState = 1;
  401.       else if ((currentDay == 12) && (currentMin >= 363) && (currentMin <= 1053)) dayState = 1;
  402.       else if ((currentDay == 13) && (currentMin >= 364) && (currentMin <= 1051)) dayState = 1;
  403.       else if ((currentDay == 14) && (currentMin >= 366) && (currentMin <= 1050)) dayState = 1;
  404.       else if ((currentDay == 15) && (currentMin >= 367) && (currentMin <= 1048)) dayState = 1;
  405.       else if ((currentDay == 16) && (currentMin >= 369) && (currentMin <= 1046)) dayState = 1;
  406.       else if ((currentDay == 17) && (currentMin >= 370) && (currentMin <= 1044)) dayState = 1;
  407.       else if ((currentDay == 18) && (currentMin >= 372) && (currentMin <= 1042)) dayState = 1;
  408.       else if ((currentDay == 19) && (currentMin >= 374) && (currentMin <= 1040)) dayState = 1;
  409.       else if ((currentDay == 20) && (currentMin >= 375) && (currentMin <= 1038)) dayState = 1;
  410.       else if ((currentDay == 21) && (currentMin >= 377) && (currentMin <= 1036)) dayState = 1;
  411.       else if ((currentDay == 22) && (currentMin >= 378) && (currentMin <= 1035)) dayState = 1;
  412.       else if ((currentDay == 23) && (currentMin >= 380) && (currentMin <= 1033)) dayState = 1;
  413.       else if ((currentDay == 24) && (currentMin >= 381) && (currentMin <= 1031)) dayState = 1;
  414.       else if ((currentDay == 25) && (currentMin >= 383) && (currentMin <= 1029)) dayState = 1;
  415.       else if ((currentDay == 26) && (currentMin >= 385) && (currentMin <= 1028)) dayState = 1;
  416.       else if ((currentDay == 27) && (currentMin >= 386) && (currentMin <= 1026)) dayState = 1;
  417.       else if ((currentDay == 28) && (currentMin >= 388) && (currentMin <= 1024)) dayState = 1;
  418.       else if ((currentDay == 29) && (currentMin >= 389) && (currentMin <= 1023)) dayState = 1;
  419.       else if ((currentDay == 30) && (currentMin >= 391) && (currentMin <= 1021)) dayState = 1;
  420.       else if ((currentDay == 31) && (currentMin >= 393) && (currentMin <= 1020)) dayState = 1;
  421.       else dayState = 0;
  422.       break;
  423.     case 11:                                                                                       //November
  424.       if ((currentDay == 1) && (currentMin >= 394) && (currentMin <= 1018)) dayState = 1;
  425.       else if ((currentDay == 2) && (currentMin >= 396) && (currentMin <= 1016)) dayState = 1;
  426.       else if ((currentDay == 3) && (currentMin >= 397) && (currentMin <= 1015)) dayState = 1;
  427.       else if ((currentDay == 4) && (currentMin >= 399) && (currentMin <= 1014)) dayState = 1;
  428.       else if ((currentDay == 5) && (currentMin >= 401) && (currentMin <= 1012)) dayState = 1;
  429.       else if ((currentDay == 6) && (currentMin >= 402) && (currentMin <= 1011)) dayState = 1;
  430.       else if ((currentDay == 7) && (currentMin >= 404) && (currentMin <= 1009)) dayState = 1;
  431.       else if ((currentDay == 8) && (currentMin >= 405) && (currentMin <= 1008)) dayState = 1;
  432.       else if ((currentDay == 9) && (currentMin >= 407) && (currentMin <= 1007)) dayState = 1;
  433.       else if ((currentDay == 10) && (currentMin >= 409) && (currentMin <= 1005)) dayState = 1;
  434.       else if ((currentDay == 11) && (currentMin >= 410) && (currentMin <= 1004)) dayState = 1;
  435.       else if ((currentDay == 12) && (currentMin >= 412) && (currentMin <= 1003)) dayState = 1;
  436.       else if ((currentDay == 13) && (currentMin >= 413) && (currentMin <= 1002)) dayState = 1;
  437.       else if ((currentDay == 14) && (currentMin >= 415) && (currentMin <= 1001)) dayState = 1;
  438.       else if ((currentDay == 15) && (currentMin >= 417) && (currentMin <= 999)) dayState = 1;
  439.       else if ((currentDay == 16) && (currentMin >= 418) && (currentMin <= 998)) dayState = 1;
  440.       else if ((currentDay == 17) && (currentMin >= 420) && (currentMin <= 997)) dayState = 1;
  441.       else if ((currentDay == 18) && (currentMin >= 421) && (currentMin <= 996)) dayState = 1;
  442.       else if ((currentDay == 19) && (currentMin >= 423) && (currentMin <= 995)) dayState = 1;
  443.       else if ((currentDay == 20) && (currentMin >= 424) && (currentMin <= 995)) dayState = 1;
  444.       else if ((currentDay == 21) && (currentMin >= 426) && (currentMin <= 994)) dayState = 1;
  445.       else if ((currentDay == 22) && (currentMin >= 427) && (currentMin <= 993)) dayState = 1;
  446.       else if ((currentDay == 23) && (currentMin >= 429) && (currentMin <= 992)) dayState = 1;
  447.       else if ((currentDay == 24) && (currentMin >= 430) && (currentMin <= 991)) dayState = 1;
  448.       else if ((currentDay == 25) && (currentMin >= 432) && (currentMin <= 991)) dayState = 1;
  449.       else if ((currentDay == 26) && (currentMin >= 433) && (currentMin <= 990)) dayState = 1;
  450.       else if ((currentDay == 27) && (currentMin >= 434) && (currentMin <= 989)) dayState = 1;
  451.       else if ((currentDay == 28) && (currentMin >= 436) && (currentMin <= 989)) dayState = 1;
  452.       else if ((currentDay == 29) && (currentMin >= 437) && (currentMin <= 988)) dayState = 1;
  453.       else if ((currentDay == 30) && (currentMin >= 438) && (currentMin <= 988)) dayState = 1;
  454.       else dayState = 0;
  455.       break;
  456.     case 12:                                                                                       //December
  457.       if ((currentDay == 1) && (currentMin >= 440) && (currentMin <= 987)) dayState = 1;
  458.       else if ((currentDay == 2) && (currentMin >= 441) && (currentMin <= 987)) dayState = 1;
  459.       else if ((currentDay == 3) && (currentMin >= 442) && (currentMin <= 987)) dayState = 1;
  460.       else if ((currentDay == 4) && (currentMin >= 443) && (currentMin <= 986)) dayState = 1;
  461.       else if ((currentDay == 5) && (currentMin >= 445) && (currentMin <= 986)) dayState = 1;
  462.       else if ((currentDay == 6) && (currentMin >= 446) && (currentMin <= 986)) dayState = 1;
  463.       else if ((currentDay == 7) && (currentMin >= 447) && (currentMin <= 986)) dayState = 1;
  464.       else if ((currentDay == 8) && (currentMin >= 448) && (currentMin <= 986)) dayState = 1;
  465.       else if ((currentDay == 9) && (currentMin >= 449) && (currentMin <= 985)) dayState = 1;
  466.       else if ((currentDay == 10) && (currentMin >= 450) && (currentMin <= 985)) dayState = 1;
  467.       else if ((currentDay == 11) && (currentMin >= 451) && (currentMin <= 985)) dayState = 1;
  468.       else if ((currentDay == 12) && (currentMin >= 452) && (currentMin <= 986)) dayState = 1;
  469.       else if ((currentDay == 13) && (currentMin >= 453) && (currentMin <= 986)) dayState = 1;
  470.       else if ((currentDay == 14) && (currentMin >= 454) && (currentMin <= 986)) dayState = 1;
  471.       else if ((currentDay == 15) && (currentMin >= 454) && (currentMin <= 986)) dayState = 1;
  472.       else if ((currentDay == 16) && (currentMin >= 455) && (currentMin <= 986)) dayState = 1;
  473.       else if ((currentDay == 17) && (currentMin >= 456) && (currentMin <= 987)) dayState = 1;
  474.       else if ((currentDay == 18) && (currentMin >= 457) && (currentMin <= 987)) dayState = 1;
  475.       else if ((currentDay == 19) && (currentMin >= 457) && (currentMin <= 987)) dayState = 1;
  476.       else if ((currentDay == 20) && (currentMin >= 458) && (currentMin <= 988)) dayState = 1;
  477.       else if ((currentDay == 21) && (currentMin >= 458) && (currentMin <= 988)) dayState = 1;
  478.       else if ((currentDay == 22) && (currentMin >= 459) && (currentMin <= 989)) dayState = 1;
  479.       else if ((currentDay == 23) && (currentMin >= 459) && (currentMin <= 989)) dayState = 1;
  480.       else if ((currentDay == 24) && (currentMin >= 460) && (currentMin <= 990)) dayState = 1;
  481.       else if ((currentDay == 25) && (currentMin >= 460) && (currentMin <= 991)) dayState = 1;
  482.       else if ((currentDay == 26) && (currentMin >= 460) && (currentMin <= 991)) dayState = 1;
  483.       else if ((currentDay == 27) && (currentMin >= 460) && (currentMin <= 992)) dayState = 1;
  484.       else if ((currentDay == 28) && (currentMin >= 461) && (currentMin <= 993)) dayState = 1;
  485.       else if ((currentDay == 29) && (currentMin >= 461) && (currentMin <= 994)) dayState = 1;
  486.       else if ((currentDay == 30) && (currentMin >= 461) && (currentMin <= 995)) dayState = 1;
  487.       else if ((currentDay == 31) && (currentMin >= 461) && (currentMin <= 995)) dayState = 1;
  488.       else dayState = 0;
  489.       break;
  490.   }
  491. }
  492.  
  493.  
  494.  
  495.  
  496. void updateMotorPos() {
  497.   if ((dayState == 1) && (digitalRead(EndstopOpened) == 0)) delay(5);       //Ak je den a dvere su otvorene nerob nic
  498.   else if ((dayState == 0) && (digitalRead(EndstopClosed) == 0)) delay(5);  //Ak je noc a dvere su zatvorene nerob nic
  499.  
  500.   else if ((dayState == 1) && (digitalRead(EndstopOpened) == 1)) {   //Ak je den a dvere niesu otvorene
  501.     digitalWrite(LED_BUILTIN, HIGH);
  502.     Hbridge(1);                             //Zacni otvarat dvere
  503.     while (digitalRead(EndstopOpened) == 1) {           //Cakaj kym neprepne endstop otvorene
  504.       delay(1);
  505.     }
  506.     Hbridge(0);                                         //Vypni motor
  507.     digitalWrite(LED_BUILTIN, LOW);
  508.   }
  509.  
  510.   else if ((dayState == 0) && (digitalRead(EndstopClosed) == 1)) {    //Ak je noc a dvere niesu zatvorene
  511.     digitalWrite(LED_BUILTIN, HIGH);
  512.     Hbridge(2);                             //Zacni zatvarat dvere
  513.     while (digitalRead(EndstopClosed) == 1) {           //Cakaj kym neprepne endstop zatvorene
  514.       delay(1);
  515.     }
  516.     Hbridge(0);                                         //Vypni motor
  517.     digitalWrite(LED_BUILTIN, LOW);
  518.   }
  519.   Hbridge(0);
  520.   digitalWrite(LED_BUILTIN, LOW);
  521. }
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. void setup() {
  533.   pinMode(3, OUTPUT);
  534.   digitalWrite(3, HIGH);
  535.   pinMode(HbridgeA, OUTPUT);
  536.   pinMode(HbridgeB, OUTPUT);
  537.   pinMode(EndstopOpened, INPUT);
  538.   pinMode(EndstopClosed, INPUT);
  539.   pinMode(Button1, INPUT_PULLUP);
  540.   pinMode(Button2, INPUT_PULLUP);
  541.   pinMode(Jumper1, INPUT_PULLUP);
  542.   pinMode(Jumper2, INPUT_PULLUP);
  543.  
  544.   rtc.begin();
  545.  
  546.   //Nastavenie času
  547.   //rtc.setDOW(SUNDAY);           //Nastavi den v tyzdni
  548.   //rtc.setTime(17, 55, 30);      //Nastavi cas (24h format)
  549.   //rtc.setDate(19, 05, 2019);    //Nastavi datum
  550.   //Cas poslednej kalibracie hodin: Nedela, 19.05.2019, 17:55:30 (SEČ)
  551.  
  552.   Serial.begin(9600);
  553.  
  554.   if (digitalRead(Jumper2) == HIGH) {                                  //Manualne ovladanie
  555.     while (1) {
  556.       if (digitalRead(Button1) == LOW) {
  557.         Hbridge(1);
  558.         while (digitalRead(Button1) == LOW) {
  559.           delay(1);
  560.         }
  561.         Hbridge(0);
  562.       }
  563.       if (digitalRead(Button2) == LOW) {
  564.         Hbridge(2);
  565.         while (digitalRead(Button2) == LOW) {
  566.           delay(1);
  567.         }
  568.         Hbridge(0);
  569.       }
  570.     }
  571.   }
  572. }
  573.  
  574.  
  575.  
  576. void loop() {
  577.  
  578.   updateDayState();                               //Aktualizuje dayState
  579.  
  580.   updateMotorPos();                               //Skontroluje stav otvorenia dveri a nastavi spravnu polohu motora
  581.  
  582.   for (int i = 0; i <= 60; i++) {                  //Caka 60 sekund na dalsiu aktualizaciu
  583.     digitalWrite(LED_BUILTIN, HIGH);
  584.     delay(50);
  585.     digitalWrite(LED_BUILTIN, LOW);
  586.     delay(950);
  587.   }
  588.  
  589.  
  590.   /*                                 //Debugging
  591.     Serial.print("Buttons: ");
  592.     Serial.print(digitalRead(Button1));
  593.     Serial.print(", ");
  594.     Serial.println(digitalRead(Button2));
  595.     Serial.print("Jumpers: ");
  596.     Serial.print(digitalRead(Jumper1));
  597.     Serial.print(", ");
  598.     Serial.println(digitalRead(Jumper2));
  599.     Serial.print("Endstops: ");
  600.     Serial.print(digitalRead(EndstopOpened));
  601.     Serial.print(", ");
  602.     Serial.println(digitalRead(EndstopClosed));
  603.     Serial.print("Actual time and date: ");
  604.     Serial.print(rtc.getDateStr());
  605.     Serial.print("     ");
  606.     Serial.println(rtc.getTimeStr());
  607.     Serial.print("dayState: ");
  608.     Serial.println(dayState);
  609.     delay(1000);
  610.   */
  611.  
  612. }
  613.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement