Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- D3 - Trvalo 5V, (OUTPUT, trvalo HIGH), napajanie pre pull-up rezistory pre endstopy
- D4 - ovladanie H mostiku strana A (OUTPUT)
- D5 - ovladanie H mostiku strana B (OUTPUT)
- D6 - Endstop 1 (INPUT)
- D7 - Endstop 2 (INPUT)
- D8 - S1 (INPUT_PULLUP)
- D9 - S2 (INPUT_PULLUP)
- D10 - NC
- D11 - JP2 (INPUT_PULLUP)
- D12 - JP1 (INPUT_PULLUP)
- */
- #include <DS3231.h>
- #define HbridgeA 4
- #define HbridgeB 5
- #define EndstopOpened 6
- #define EndstopClosed 7
- #define Button1 8
- #define Button2 9
- #define Jumper1 12
- #define Jumper2 11
- DS3231 rtc(SDA, SCL);
- Time t;
- boolean dayState = 1; //Stav dna (den-1 / noc-0)
- void Hbridge(short state) {
- switch (state) {
- case 1: //Otvaranie dveri
- digitalWrite(HbridgeB, LOW);
- delayMicroseconds(10);
- for (int i = 1; i < 1000; i++) { //Softstart funkcia
- digitalWrite(HbridgeA, LOW);
- delayMicroseconds(1000 - i);
- digitalWrite(HbridgeA, HIGH);
- delayMicroseconds(i);
- }
- break;
- case 2: //Zatvaranie dveri
- digitalWrite(HbridgeA, LOW);
- delayMicroseconds(10);
- for (int i = 1; i < 1000; i++) { //Softstart funkcia
- digitalWrite(HbridgeB, LOW);
- delayMicroseconds(1000 - i);
- digitalWrite(HbridgeB, HIGH);
- delayMicroseconds(i);
- }
- break;
- default: //Vypnutie motoru
- digitalWrite(HbridgeA, LOW);
- digitalWrite(HbridgeB, LOW);
- break;
- }
- }
- void updateDayState() { //Funkcia pre zistenie ci je svetlo alebo nie
- t = rtc.getTime(); //Ziska aktualny cas z RTC modulu
- int currentMin = ((t.hour * 60) + t.min);
- int currentDay = (t.date);
- String currentMonthStr = rtc.getMonthStr();
- int currentMonth;
- if (currentMonthStr == "January") currentMonth = 1; //Premeni nazvy mesiacov na cisla
- else if (currentMonthStr == "February") currentMonth = 2;
- else if (currentMonthStr == "March") currentMonth = 3;
- else if (currentMonthStr == "April") currentMonth = 4;
- else if (currentMonthStr == "May") currentMonth = 5;
- else if (currentMonthStr == "June") currentMonth = 6;
- else if (currentMonthStr == "July") currentMonth = 7;
- else if (currentMonthStr == "August") currentMonth = 8;
- else if (currentMonthStr == "September") currentMonth = 9;
- else if (currentMonthStr == "October") currentMonth = 10;
- else if (currentMonthStr == "November") currentMonth = 11;
- else if (currentMonthStr == "December") currentMonth = 12;
- switch (currentMonth) {
- case 1: //Január
- if ((currentDay == 1) && (currentMin >= 461) && (currentMin <= 996)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 461) && (currentMin <= 997)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 461) && (currentMin <= 998)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 461) && (currentMin <= 999)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 460) && (currentMin <= 1000)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 460) && (currentMin <= 1001)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 460) && (currentMin <= 1002)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 460) && (currentMin <= 1003)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 459) && (currentMin <= 1004)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 459) && (currentMin <= 1005)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 458) && (currentMin <= 1006)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 458) && (currentMin <= 1008)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 457) && (currentMin <= 1009)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 456) && (currentMin <= 1010)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 456) && (currentMin <= 1012)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 455) && (currentMin <= 1013)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 454) && (currentMin <= 1014)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 454) && (currentMin <= 1016)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 453) && (currentMin <= 1017)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 452) && (currentMin <= 1018)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 451) && (currentMin <= 1020)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 450) && (currentMin <= 1021)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 449) && (currentMin <= 1023)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 448) && (currentMin <= 1024)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 447) && (currentMin <= 1026)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 446) && (currentMin <= 1027)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 444) && (currentMin <= 1029)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 443) && (currentMin <= 1030)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 442) && (currentMin <= 1032)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 441) && (currentMin <= 1033)) dayState = 1;
- else if ((currentDay == 31) && (currentMin >= 439) && (currentMin <= 1035)) dayState = 1;
- else dayState = 0;
- break;
- case 2: //Február
- if ((currentDay == 1) && (currentMin >= 438) && (currentMin <= 1036)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 437) && (currentMin <= 1038)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 435) && (currentMin <= 1039)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 434) && (currentMin <= 1041)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 432) && (currentMin <= 1042)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 431) && (currentMin <= 1044)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 429) && (currentMin <= 1046)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 428) && (currentMin <= 1047)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 426) && (currentMin <= 1049)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 424) && (currentMin <= 1050)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 423) && (currentMin <= 1052)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 421) && (currentMin <= 1053)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 420) && (currentMin <= 1055)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 418) && (currentMin <= 1057)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 416) && (currentMin <= 1058)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 414) && (currentMin <= 1060)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 413) && (currentMin <= 1061)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 411) && (currentMin <= 1063)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 409) && (currentMin <= 1064)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 407) && (currentMin <= 1066)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 405) && (currentMin <= 1068)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 403) && (currentMin <= 1069)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 401) && (currentMin <= 1071)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 400) && (currentMin <= 1072)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 398) && (currentMin <= 1074)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 396) && (currentMin <= 1076)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 394) && (currentMin <= 1077)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 392) && (currentMin <= 1079)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 390) && (currentMin <= 1080)) dayState = 1;
- else dayState = 0;
- break;
- case 3: //Marec
- if ((currentDay == 1) && (currentMin >= 388) && (currentMin <= 1082)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 386) && (currentMin <= 1083)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 384) && (currentMin <= 1085)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 382) && (currentMin <= 1086)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 380) && (currentMin <= 1088)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 378) && (currentMin <= 1090)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 376) && (currentMin <= 1091)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 374) && (currentMin <= 1093)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 372) && (currentMin <= 1094)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 369) && (currentMin <= 1096)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 367) && (currentMin <= 1097)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 365) && (currentMin <= 1099)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 363) && (currentMin <= 1100)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 361) && (currentMin <= 1102)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 359) && (currentMin <= 1104)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 357) && (currentMin <= 1105)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 355) && (currentMin <= 1107)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 353) && (currentMin <= 1108)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 351) && (currentMin <= 1110)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 348) && (currentMin <= 1111)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 346) && (currentMin <= 1113)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 344) && (currentMin <= 1114)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 342) && (currentMin <= 1116)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 340) && (currentMin <= 1118)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 338) && (currentMin <= 1119)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 336) && (currentMin <= 1121)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 334) && (currentMin <= 1122)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 332) && (currentMin <= 1124)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 329) && (currentMin <= 1125)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 327) && (currentMin <= 1127)) dayState = 1;
- else if ((currentDay == 31) && (currentMin >= 325) && (currentMin <= 1129)) dayState = 1;
- else dayState = 0;
- break;
- case 4: //Apríl
- if ((currentDay == 1) && (currentMin >= 323) && (currentMin <= 1130)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 321) && (currentMin <= 1132)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 319) && (currentMin <= 1133)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 317) && (currentMin <= 1135)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 315) && (currentMin <= 1136)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 313) && (currentMin <= 1138)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 311) && (currentMin <= 1140)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 309) && (currentMin <= 1141)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 306) && (currentMin <= 1143)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 304) && (currentMin <= 1144)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 302) && (currentMin <= 1146)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 300) && (currentMin <= 1148)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 298) && (currentMin <= 1149)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 296) && (currentMin <= 1151)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 294) && (currentMin <= 1153)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 292) && (currentMin <= 1154)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 290) && (currentMin <= 1156)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 288) && (currentMin <= 1157)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 287) && (currentMin <= 1159)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 285) && (currentMin <= 1161)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 283) && (currentMin <= 1162)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 281) && (currentMin <= 1164)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 279) && (currentMin <= 1166)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 277) && (currentMin <= 1167)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 275) && (currentMin <= 1169)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 273) && (currentMin <= 1171)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 272) && (currentMin <= 1172)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 270) && (currentMin <= 1174)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 268) && (currentMin <= 1176)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 266) && (currentMin <= 1177)) dayState = 1;
- else dayState = 0;
- break;
- case 5: //Máj
- if ((currentDay == 1) && (currentMin >= 265) && (currentMin <= 1179)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 263) && (currentMin <= 1181)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 261) && (currentMin <= 1182)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 260) && (currentMin <= 1184)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 258) && (currentMin <= 1185)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 256) && (currentMin <= 1187)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 255) && (currentMin <= 1189)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 253) && (currentMin <= 1190)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 252) && (currentMin <= 1192)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 250) && (currentMin <= 1194)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 249) && (currentMin <= 1195)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 247) && (currentMin <= 1197)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 246) && (currentMin <= 1198)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 245) && (currentMin <= 1200)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 243) && (currentMin <= 1201)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 242) && (currentMin <= 1203)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 241) && (currentMin <= 1204)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 239) && (currentMin <= 1206)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 238) && (currentMin <= 1207)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 237) && (currentMin <= 1209)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 236) && (currentMin <= 1210)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 235) && (currentMin <= 1212)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 234) && (currentMin <= 1213)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 233) && (currentMin <= 1214)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 232) && (currentMin <= 1216)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 231) && (currentMin <= 1217)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 230) && (currentMin <= 1218)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 229) && (currentMin <= 1220)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 228) && (currentMin <= 1221)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 227) && (currentMin <= 1222)) dayState = 1;
- else if ((currentDay == 31) && (currentMin >= 227) && (currentMin <= 1223)) dayState = 1;
- else dayState = 0;
- break;
- case 6: //Jún
- if ((currentDay == 1) && (currentMin >= 226) && (currentMin <= 1224)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 225) && (currentMin <= 1226)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 225) && (currentMin <= 1227)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 224) && (currentMin <= 1228)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 224) && (currentMin <= 1229)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 223) && (currentMin <= 1230)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 223) && (currentMin <= 1230)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 222) && (currentMin <= 1231)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 222) && (currentMin <= 1232)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 222) && (currentMin <= 1233)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 221) && (currentMin <= 1234)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 221) && (currentMin <= 1234)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 221) && (currentMin <= 1235)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 221) && (currentMin <= 1235)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 221) && (currentMin <= 1236)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 221) && (currentMin <= 1236)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 221) && (currentMin <= 1237)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 221) && (currentMin <= 1237)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 221) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 221) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 221) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 222) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 222) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 222) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 223) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 223) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 224) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 224) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 225) && (currentMin <= 1238)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 225) && (currentMin <= 1237)) dayState = 1;
- else dayState = 0;
- break;
- case 7: //Júl
- if ((currentDay == 1) && (currentMin >= 226) && (currentMin <= 1237)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 226) && (currentMin <= 1236)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 227) && (currentMin <= 1236)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 228) && (currentMin <= 1235)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 229) && (currentMin <= 1235)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 229) && (currentMin <= 1234)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 230) && (currentMin <= 1234)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 231) && (currentMin <= 1233)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 232) && (currentMin <= 1232)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 233) && (currentMin <= 1231)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 234) && (currentMin <= 1230)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 235) && (currentMin <= 1229)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 236) && (currentMin <= 1228)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 237) && (currentMin <= 1227)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 238) && (currentMin <= 1226)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 239) && (currentMin <= 1225)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 240) && (currentMin <= 1224)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 241) && (currentMin <= 1223)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 243) && (currentMin <= 1222)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 244) && (currentMin <= 1220)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 245) && (currentMin <= 1219)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 246) && (currentMin <= 1218)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 247) && (currentMin <= 1216)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 249) && (currentMin <= 1215)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 250) && (currentMin <= 1214)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 251) && (currentMin <= 1212)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 252) && (currentMin <= 1211)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 254) && (currentMin <= 1209)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 255) && (currentMin <= 1207)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 256) && (currentMin <= 1206)) dayState = 1;
- else if ((currentDay == 31) && (currentMin >= 258) && (currentMin <= 1204)) dayState = 1;
- else dayState = 0;
- break;
- case 8: //August
- if ((currentDay == 1) && (currentMin >= 259) && (currentMin <= 1203)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 260) && (currentMin <= 1201)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 262) && (currentMin <= 1199)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 263) && (currentMin <= 1197)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 265) && (currentMin <= 1196)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 266) && (currentMin <= 1194)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 267) && (currentMin <= 1192)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 269) && (currentMin <= 1190)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 270) && (currentMin <= 1188)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 272) && (currentMin <= 1186)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 273) && (currentMin <= 1184)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 274) && (currentMin <= 1183)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 276) && (currentMin <= 1181)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 277) && (currentMin <= 1179)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 279) && (currentMin <= 1177)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 280) && (currentMin <= 1175)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 282) && (currentMin <= 1173)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 283) && (currentMin <= 1171)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 284) && (currentMin <= 1169)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 286) && (currentMin <= 1167)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 287) && (currentMin <= 1164)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 289) && (currentMin <= 1162)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 290) && (currentMin <= 1160)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 292) && (currentMin <= 1158)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 293) && (currentMin <= 1156)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 294) && (currentMin <= 1154)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 296) && (currentMin <= 1152)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 297) && (currentMin <= 1150)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 299) && (currentMin <= 1148)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 300) && (currentMin <= 1145)) dayState = 1;
- else if ((currentDay == 31) && (currentMin >= 302) && (currentMin <= 1143)) dayState = 1;
- else dayState = 0;
- break;
- case 9: //September
- if ((currentDay == 1) && (currentMin >= 303) && (currentMin <= 1141)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 304) && (currentMin <= 1139)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 306) && (currentMin <= 1137)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 307) && (currentMin <= 1135)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 309) && (currentMin <= 1132)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 310) && (currentMin <= 1130)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 312) && (currentMin <= 1128)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 313) && (currentMin <= 1126)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 314) && (currentMin <= 1124)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 316) && (currentMin <= 1121)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 317) && (currentMin <= 1119)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 319) && (currentMin <= 1117)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 320) && (currentMin <= 1115)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 322) && (currentMin <= 1113)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 323) && (currentMin <= 1110)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 324) && (currentMin <= 1108)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 326) && (currentMin <= 1106)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 327) && (currentMin <= 1104)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 329) && (currentMin <= 1102)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 330) && (currentMin <= 1099)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 332) && (currentMin <= 1097)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 333) && (currentMin <= 1095)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 335) && (currentMin <= 1093)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 336) && (currentMin <= 1091)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 337) && (currentMin <= 1089)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 339) && (currentMin <= 1087)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 340) && (currentMin <= 1084)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 342) && (currentMin <= 1082)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 343) && (currentMin <= 1080)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 345) && (currentMin <= 1078)) dayState = 1;
- else dayState = 0;
- break;
- case 10: //Október
- if ((currentDay == 1) && (currentMin >= 346) && (currentMin <= 1076)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 348) && (currentMin <= 1074)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 349) && (currentMin <= 1072)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 351) && (currentMin <= 1070)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 352) && (currentMin <= 1068)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 354) && (currentMin <= 1066)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 355) && (currentMin <= 1063)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 357) && (currentMin <= 1061)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 358) && (currentMin <= 1059)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 360) && (currentMin <= 1057)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 361) && (currentMin <= 1055)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 363) && (currentMin <= 1053)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 364) && (currentMin <= 1051)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 366) && (currentMin <= 1050)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 367) && (currentMin <= 1048)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 369) && (currentMin <= 1046)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 370) && (currentMin <= 1044)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 372) && (currentMin <= 1042)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 374) && (currentMin <= 1040)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 375) && (currentMin <= 1038)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 377) && (currentMin <= 1036)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 378) && (currentMin <= 1035)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 380) && (currentMin <= 1033)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 381) && (currentMin <= 1031)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 383) && (currentMin <= 1029)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 385) && (currentMin <= 1028)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 386) && (currentMin <= 1026)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 388) && (currentMin <= 1024)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 389) && (currentMin <= 1023)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 391) && (currentMin <= 1021)) dayState = 1;
- else if ((currentDay == 31) && (currentMin >= 393) && (currentMin <= 1020)) dayState = 1;
- else dayState = 0;
- break;
- case 11: //November
- if ((currentDay == 1) && (currentMin >= 394) && (currentMin <= 1018)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 396) && (currentMin <= 1016)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 397) && (currentMin <= 1015)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 399) && (currentMin <= 1014)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 401) && (currentMin <= 1012)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 402) && (currentMin <= 1011)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 404) && (currentMin <= 1009)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 405) && (currentMin <= 1008)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 407) && (currentMin <= 1007)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 409) && (currentMin <= 1005)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 410) && (currentMin <= 1004)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 412) && (currentMin <= 1003)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 413) && (currentMin <= 1002)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 415) && (currentMin <= 1001)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 417) && (currentMin <= 999)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 418) && (currentMin <= 998)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 420) && (currentMin <= 997)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 421) && (currentMin <= 996)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 423) && (currentMin <= 995)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 424) && (currentMin <= 995)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 426) && (currentMin <= 994)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 427) && (currentMin <= 993)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 429) && (currentMin <= 992)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 430) && (currentMin <= 991)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 432) && (currentMin <= 991)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 433) && (currentMin <= 990)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 434) && (currentMin <= 989)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 436) && (currentMin <= 989)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 437) && (currentMin <= 988)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 438) && (currentMin <= 988)) dayState = 1;
- else dayState = 0;
- break;
- case 12: //December
- if ((currentDay == 1) && (currentMin >= 440) && (currentMin <= 987)) dayState = 1;
- else if ((currentDay == 2) && (currentMin >= 441) && (currentMin <= 987)) dayState = 1;
- else if ((currentDay == 3) && (currentMin >= 442) && (currentMin <= 987)) dayState = 1;
- else if ((currentDay == 4) && (currentMin >= 443) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 5) && (currentMin >= 445) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 6) && (currentMin >= 446) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 7) && (currentMin >= 447) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 8) && (currentMin >= 448) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 9) && (currentMin >= 449) && (currentMin <= 985)) dayState = 1;
- else if ((currentDay == 10) && (currentMin >= 450) && (currentMin <= 985)) dayState = 1;
- else if ((currentDay == 11) && (currentMin >= 451) && (currentMin <= 985)) dayState = 1;
- else if ((currentDay == 12) && (currentMin >= 452) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 13) && (currentMin >= 453) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 14) && (currentMin >= 454) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 15) && (currentMin >= 454) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 16) && (currentMin >= 455) && (currentMin <= 986)) dayState = 1;
- else if ((currentDay == 17) && (currentMin >= 456) && (currentMin <= 987)) dayState = 1;
- else if ((currentDay == 18) && (currentMin >= 457) && (currentMin <= 987)) dayState = 1;
- else if ((currentDay == 19) && (currentMin >= 457) && (currentMin <= 987)) dayState = 1;
- else if ((currentDay == 20) && (currentMin >= 458) && (currentMin <= 988)) dayState = 1;
- else if ((currentDay == 21) && (currentMin >= 458) && (currentMin <= 988)) dayState = 1;
- else if ((currentDay == 22) && (currentMin >= 459) && (currentMin <= 989)) dayState = 1;
- else if ((currentDay == 23) && (currentMin >= 459) && (currentMin <= 989)) dayState = 1;
- else if ((currentDay == 24) && (currentMin >= 460) && (currentMin <= 990)) dayState = 1;
- else if ((currentDay == 25) && (currentMin >= 460) && (currentMin <= 991)) dayState = 1;
- else if ((currentDay == 26) && (currentMin >= 460) && (currentMin <= 991)) dayState = 1;
- else if ((currentDay == 27) && (currentMin >= 460) && (currentMin <= 992)) dayState = 1;
- else if ((currentDay == 28) && (currentMin >= 461) && (currentMin <= 993)) dayState = 1;
- else if ((currentDay == 29) && (currentMin >= 461) && (currentMin <= 994)) dayState = 1;
- else if ((currentDay == 30) && (currentMin >= 461) && (currentMin <= 995)) dayState = 1;
- else if ((currentDay == 31) && (currentMin >= 461) && (currentMin <= 995)) dayState = 1;
- else dayState = 0;
- break;
- }
- }
- void updateMotorPos() {
- if ((dayState == 1) && (digitalRead(EndstopOpened) == 0)) delay(5); //Ak je den a dvere su otvorene nerob nic
- else if ((dayState == 0) && (digitalRead(EndstopClosed) == 0)) delay(5); //Ak je noc a dvere su zatvorene nerob nic
- else if ((dayState == 1) && (digitalRead(EndstopOpened) == 1)) { //Ak je den a dvere niesu otvorene
- digitalWrite(LED_BUILTIN, HIGH);
- Hbridge(1); //Zacni otvarat dvere
- while (digitalRead(EndstopOpened) == 1) { //Cakaj kym neprepne endstop otvorene
- delay(1);
- }
- Hbridge(0); //Vypni motor
- digitalWrite(LED_BUILTIN, LOW);
- }
- else if ((dayState == 0) && (digitalRead(EndstopClosed) == 1)) { //Ak je noc a dvere niesu zatvorene
- digitalWrite(LED_BUILTIN, HIGH);
- Hbridge(2); //Zacni zatvarat dvere
- while (digitalRead(EndstopClosed) == 1) { //Cakaj kym neprepne endstop zatvorene
- delay(1);
- }
- Hbridge(0); //Vypni motor
- digitalWrite(LED_BUILTIN, LOW);
- }
- Hbridge(0);
- digitalWrite(LED_BUILTIN, LOW);
- }
- void setup() {
- pinMode(3, OUTPUT);
- digitalWrite(3, HIGH);
- pinMode(HbridgeA, OUTPUT);
- pinMode(HbridgeB, OUTPUT);
- pinMode(EndstopOpened, INPUT);
- pinMode(EndstopClosed, INPUT);
- pinMode(Button1, INPUT_PULLUP);
- pinMode(Button2, INPUT_PULLUP);
- pinMode(Jumper1, INPUT_PULLUP);
- pinMode(Jumper2, INPUT_PULLUP);
- rtc.begin();
- //Nastavenie času
- //rtc.setDOW(SUNDAY); //Nastavi den v tyzdni
- //rtc.setTime(17, 55, 30); //Nastavi cas (24h format)
- //rtc.setDate(19, 05, 2019); //Nastavi datum
- //Cas poslednej kalibracie hodin: Nedela, 19.05.2019, 17:55:30 (SEČ)
- Serial.begin(9600);
- if (digitalRead(Jumper2) == HIGH) { //Manualne ovladanie
- while (1) {
- if (digitalRead(Button1) == LOW) {
- Hbridge(1);
- while (digitalRead(Button1) == LOW) {
- delay(1);
- }
- Hbridge(0);
- }
- if (digitalRead(Button2) == LOW) {
- Hbridge(2);
- while (digitalRead(Button2) == LOW) {
- delay(1);
- }
- Hbridge(0);
- }
- }
- }
- }
- void loop() {
- updateDayState(); //Aktualizuje dayState
- updateMotorPos(); //Skontroluje stav otvorenia dveri a nastavi spravnu polohu motora
- for (int i = 0; i <= 60; i++) { //Caka 60 sekund na dalsiu aktualizaciu
- digitalWrite(LED_BUILTIN, HIGH);
- delay(50);
- digitalWrite(LED_BUILTIN, LOW);
- delay(950);
- }
- /* //Debugging
- Serial.print("Buttons: ");
- Serial.print(digitalRead(Button1));
- Serial.print(", ");
- Serial.println(digitalRead(Button2));
- Serial.print("Jumpers: ");
- Serial.print(digitalRead(Jumper1));
- Serial.print(", ");
- Serial.println(digitalRead(Jumper2));
- Serial.print("Endstops: ");
- Serial.print(digitalRead(EndstopOpened));
- Serial.print(", ");
- Serial.println(digitalRead(EndstopClosed));
- Serial.print("Actual time and date: ");
- Serial.print(rtc.getDateStr());
- Serial.print(" ");
- Serial.println(rtc.getTimeStr());
- Serial.print("dayState: ");
- Serial.println(dayState);
- delay(1000);
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement