[{{mminutes}}:{{sseconds}}] X
Пользователь приглашает вас присоединиться к открытой игре игре с друзьями .
программируй на 1000
(0)       Используют 2 человека

Комментарии

Ни одного комментария.
Написать тут
Описание:
Команды C++
Автор:
x-sakaev
Создан:
8 июля 2022 в 09:02
Публичный:
Нет
Тип словаря:
Фразы
В этом режиме перемешиваться будут не слова, а целые фразы, разделенные переносом строки.
Содержание:
1 #include <Arduino.h>
2 #include <LiquidCrystal_I2C.h>
3 #include <GyverButton.h>
4 #include <GyverEncoder.h>
5 #include <GyverTimer.h>
6 #include <bigNumbers.h>
7 #include <GyverPower.h>
8 #include <EEPROM.h>
9 #define DELETEL 0
10 #define TONE_PIN 10
11 LiquidCrystal_I2C lcd(0x27, 20, 4);
12 bigNumbers<LiquidCrystal_I2C> bigNumbersLcd(&lcd);
13 GButton butt_mode(2);
14 GButton butt_settings(3);
15 GButton sensor(12);
16 GTimer time(MS);
17 GTimer enc_show(MS);
18 GTimer sleeper(MS);
19 GTimer melod(MS);
20 GTimer off(MS);
21 Encoder enc(6, 7, ENC_NO_BUTTON, TYPE2);
22 bool isBacklight = true;
23 static signed char days = 0;
24 static signed char hours = 0;
25 static signed char minets = 0;
26 bool zaran_off = false;
27 bool wokeUpper()
28 {
29 if (!isBacklight)
30 {
31 lcd.backlight();
32 isBacklight = true;
33 sleeper.setInterval(30000 >> DELETEL);
34 return false;
35 }
36 sleeper.setInterval(30000 >> DELETEL);
37 return true;
38 }
39 void ee_save0();
40 void ee_save1();
41 #include <mode1.h>
42 #include <mode0.h>
43 #include <symbols.h>
44 #include <melod.h>
45 void ee_save0()
46 {
47 EEPROM.put(0, days);
48 EEPROM.put(1, hours);
49 EEPROM.put(2, minets);
50 }
51 void ee_save1()
52 {
53 for (char i = 0; i < 4; i++)
54 {
55 EEPROM.put(3 + (10 * i), alar[(int)i].hs);
56 EEPROM.put(4 + (10 * i), alar[(int)i].ms);
57 EEPROM.put(5 + (10 * i), alar[(int)i].isBring);
58 for (int j = 0; j < 7; j++)
59 {
60 EEPROM[6 + (10 * i) + j] = alar[(int)i].ds[j];
61 }
62 }
63 }
64 void setup()
65 {
66 //* lcd
67 lcd.backlight();
68 lcd.init();
69 lcd.backlight();
70 lcd.createChar(3, doubledot);
71 lcd.createChar(4, uperrow);
72 lcd.createChar(5, lefterrow);
73 bigNumbersLcd.intNumbers();
74 //* buttons and encoder
75 butt_settings.setTimeout(1000 >> DELETEL);
76 butt_mode.setTickMode(AUTO);
77 butt_mode.setDebounce(20 >> DELETEL);
78 butt_settings.setTickMode(AUTO);
79 butt_settings.setDebounce(20 >> DELETEL);
80 sensor.setDebounce(50 >> DELETEL);
81 sensor.setTimeout(800 >> DELETEL);
82 sensor.setClickTimeout(1000 >> DELETEL);
83 sensor.setType(HIGH_PULL);
84 sensor.setDirection(NORM_CLOSE);
85 enc.setTickMode(AUTO);
86 //* timers
87 enc_show.setTimeout(250 >> DELETEL);
88 enc_show.reset();
89 time.setInterval(60000 >> DELETEL);
90 wokeUpper();
91 //* power
92 power.hardwareDisable(PWR_SPI | PWR_ADC);
93 // power.setSystemPrescaler(PRESCALER_2);
94 //* EEPROM
95 EEPROM.get(0, days);
96 EEPROM.get(1, hours);
97 EEPROM.get(2, minets);
98 days %= 7;
99 hours %= 24;
100 minets %= 60;
101 for (char i = 0; i < 4; i++)
102 {
103 EEPROM.get(3 + (10 * i), alar[(int)i].hs);
104 EEPROM.get(4 + (10 * i), alar[(int)i].ms);
105 alar[(int)i].isBring = (bool)EEPROM[5 + (10 * i)];
106 for (int j = 0; j < 7; j++)
107 {
108 alar[(int)i].ds[j] = (bool)EEPROM[6 + (10 * i) + j];
109 }
110 alar[(int)i].hs %= 24;
111 alar[(int)i].ms %= 60;
112 alar[(int)i].get();
113 }
114 }
115 void loop()
116 {
117 static bool perex = true;
118 static signed char mode = 0;
119 static unsigned int j = 0;
120 static char theAlarm = 255;
121 sensor.tick();
122 if (time.isReady())
123 {
124 minets += 1;
125 if (minets >= 60)
126 {
127 minets = 0;
128 hours += 1;
129 if (hours >= 24)
130 {
131 hours = 0;
132 days = (days + 1) % 7;
133 }
134 }
135 ee_save0();
136 }
137 if (butt_mode.isClick())
138 {
139 if (wokeUpper())
140 {
141 mode = (mode + 1) % 2;
142 perex = true;
143 }
144 }
145 if (mode == 0)
146 {
147 mode = mode0(minets, hours, days, perex);
148 }
149 else if (mode == 1)
150 {
151 mode = mode1(perex);
152 }
153 perex = false;
154 for (char i = 0; i < 4; i++)
155 {
156 if (alar[(int)i].isBringing(minets, hours, days))
157 {
158 if (!zaran_off)
159 {
160 if (alar[(int)i].bringin_on)
161 {
162 wokeUpper();
163 melod.setTimeout(100 << DELETEL);
164 alar[(int)i].bringin_on = false;
165 theAlarm = i;
166 break;
167 }
168 }
169 }
170 else
171 {
172 alar[(int)i].bringin_on = true;
173 if (i == theAlarm)
174 {
175 j = 0;
176 melod.stop();
177 theAlarm = 255;
178 }
179 }
180 }
181 if (melod.isReady())
182 {
183 tone(10, pgm_read_dword(&freqs[j]), pgm_read_float(&lens[j]));
184 melod.setTimeout(pgm_read_float(&pas[j]));
185 j = (j + 1) % 269;
186 }
187 if (sensor.isClick())
188 {
189 wokeUpper();
190 alar[(int)theAlarm].bringin_on = false;
191 if (theAlarm != 255)
192 {
193 j = 0;
194 melod.stop();
195 theAlarm = 255;
196 }
197 }
198 if (sensor.isTriple())
199 {
200 zaran_off = true;
201 off.setTimeout(120000);
202 perex = true;
203 }
204 if (off.isReady())
205 {
206 zaran_off = false;
207 }
208 if (sleeper.isReady())
209 {
210 lcd.noBacklight();
211 isBacklight = false;
212 }
213 }
214 signed char mode0(signed char &minets, signed char &hours, signed char &days, bool perex)
215 {
216 signed char m = 0;
217 static signed char minets_ = 0;
218 static bool settings = false;
219 static signed char hours_set = hours;
220 static signed char minets_set = minets;
221 static signed char days_set = days;
222 static signed char mode_setting = 0;
223 char day[10] = "";
224 char day_set[10] = "";
225 char fastAlarm = (alar[0].time(minets, hours, days) <= alar[1].time(minets, hours, days)) ? 0 : 1;
226 fastAlarm = (alar[(int)fastAlarm].time(minets, hours, days) <= alar[2].time(minets, hours, days)) ? fastAlarm : 2;
227 fastAlarm = (alar[(int)fastAlarm].time(minets, hours, days) <= alar[3].time(minets, hours, days)) ? fastAlarm : 3;
228 if (perex)
229 {
230 settings = false;
231 ee_save0();
232 }
233 if (butt_settings.isClick())
234 {
235 if (wokeUpper())
236 {
237 mode_setting = (mode_setting + 1) % 3;
238 perex = true;
239 }
240 }
241 if (butt_settings.isHolded())
242 {
243 if (wokeUpper())
244 {
245 if (!settings)
246 {
247 settings = true;
248 perex = true;
249 hours_set = hours;
250 minets_set = minets;
251 days_set = days;
252 }
253 else
254 {
255 settings = false;
256 perex = true;
257 hours = hours_set;
258 minets = minets_set;
259 days = days_set;
260 time.reset();
261 ee_save0();
262 }
263 }
264 }
265 if (enc_show.isReady())
266 {
267 perex = true;
268 }
269 switch (days)
270 {
271 case 0:
272 strcpy(day, "Monday");
273 break;
274 case 1:
275 strcpy(day, "Tuesday");
276 break;
277 case 2:
278 strcpy(day, "Wednesday");
279 break;
280 case 3:
281 strcpy(day, "Thursday");
282 break;
283 case 4:
284 strcpy(day, "Friday");
285 break;
286 case 5:
287 strcpy(day, "Saturday");
288 break;
289 case 6:
290 strcpy(day, "Sunday");
291 break;
292 }
293 switch (days_set)
294 {
295 case 0:
296 strcpy(day_set, "Monday");
297 break;
298 case 1:
299 strcpy(day_set, "Tuesday");
300 break;
301 case 2:
302 strcpy(day_set, "Wednesday");
303 break;
304 case 3:
305 strcpy(day_set, "Thersday");
306 break;
307 case 4:
308 strcpy(day_set, "Friday");
309 break;
310 case 5:
311 strcpy(day_set, "Saturday");
312 break;
313 case 6:
314 strcpy(day_set, "Sunday");
315 break;
316 }
317 if (!settings)
318 {
319 mode_setting = 0;
320 if ((minets_ != minets) || (perex))
321 {
322 //* display
323 lcd.clear();
324 signed char a = hours / 10;
325 signed char b = hours % 10;
326 signed char c = minets / 10;
327 signed char d = minets % 10;
328 bigNumbersLcd.printNumber(a, 0, 0);
329 bigNumbersLcd.printNumber(b, 4, 0);
330 bigNumbersLcd.printNumber(c, 12, 0);
331 bigNumbersLcd.printNumber(d, 16, 0);
332 lcd.setCursor(9, 0);
333 lcd.write(3);
334 lcd.setCursor(9, 1);
335 lcd.write(3);
336 lcd.setCursor(0, 3);
337 lcd.print(day);
338 if (alar[(int)fastAlarm].time(minets, hours, days) != INT16_MAX)
339 {
340 lcd.setCursor(11, 3);
341 if (zaran_off)
342 {
343 lcd.print("off");
344 }
345 else
346 {
347 char bz[10] = "";
348 strcat(bz, alar[(int)fastAlarm].a);
349 strcat(bz, alar[(int)fastAlarm].b);
350 strcat(bz, ":");
351 strcat(bz, alar[(int)fastAlarm].c);
352 strcat(bz, alar[(int)fastAlarm].d);
353 strcat(bz, " ");
354 switch (alar[(int)fastAlarm].bliz_den)
355 {
356 case 0:
357 strcat(bz, "Mo");
358 break;
359 case 1:
360 strcat(bz, "Tu");
361 break;
362 case 2:
363 strcat(bz, "We");
364 break;
365 case 3:
366 strcat(bz, "Th");
367 break;
368 case 4:
369 strcat(bz, "Fr");
370 break;
371 case 5:
372 strcat(bz, "Sa");
373 break;
374 case 6:
375 strcat(bz, "Su");
376 break;
377 default:
378 strcat(bz, ">7d");
379 }
380 lcd.print(bz);
381 }
382 }
383 }
384 }
385 else
386 {
387 if (enc.isLeft())
388 {
389 if (mode_setting == 0)
390 {
391 hours_set--;
392 enc_show.setTimeout(250 >> DELETEL);
393 }
394 else if (mode_setting == 1)
395 {
396 minets_set--;
397 enc_show.setTimeout(250 >> DELETEL);
398 }
399 else if (mode_setting == 2)
400 {
401 days_set--;
402 enc_show.setTimeout(250 >> DELETEL);
403 }
404 }
405 else if (enc.isRight())
406 {
407 if (mode_setting == 0)
408 {
409 hours_set++;
410 enc_show.setTimeout(250 >> DELETEL);
411 }
412 else if (mode_setting == 1)
413 {
414 minets_set++;
415 enc_show.setTimeout(250 >> DELETEL);
416 }
417 else if (mode_setting == 2)
418 {
419 days_set++;
420 enc_show.setTimeout(250 >> DELETEL);
421 }
422 }
423 if (days_set >= 7)
424 {
425 days_set = days_set % 7;
426 }
427 else if (days_set < 0)
428 {
429 days_set = 7 + days_set;
430 }
431 if (hours_set >= 24)
432 {
433 hours_set = hours_set % 24;
434 }
435 else if (hours_set < 0)
436 {
437 hours_set = 24 + hours_set;
438 }
439 if (minets_set >= 60)
440 {
441 minets_set = minets_set % 60;
442 }
443 else if (minets_set < 0)
444 {
445 minets_set = 60 + minets_set;
446 }
447 if (perex)
448 {
449 //* display
450 lcd.clear();
451 lcd.print("SETTINGS");
452 lcd.setCursor(0, 1);
453 char a[6];
454 itoa(int(hours_set / 10), a, DEC);
455 itoa((hours_set % 10), a + 1, DEC);
456 strcpy(a + 2, ":");
457 itoa((minets_set / 10), a + 3, DEC);
458 itoa((minets_set % 10), a + 4, DEC);
459 lcd.print(a);
460 lcd.setCursor(7, 1);
461 lcd.print(day_set);
462 if (mode_setting == 0)
463 {
464 lcd.setCursor(0, 2);
465 }
466 else if (mode_setting == 1)
467 {
468 lcd.setCursor(3, 2);
469 }
470 else if (mode_setting == 2)
471 {
472 lcd.setCursor(7, 2);
473 }
474 lcd.write(4);
475 lcd.write(4);
476 }
477 }
478 minets_ = minets;
479 return m;
480 }
481 class Alarmer
482 {
483 public:
484 bool bringin_on = true;
485 bool isBring = false;
486 signed char ms;
487 signed char hs;
488 bool ds[7];
489 char a[2] = "0";
490 char b[2] = "0";
491 char c[2] = "0";
492 char d[2] = "0";
493 char e[8] = "";
494 char text[18] = "00:00 | MTWTFSS |";
495 char bliz_den = 45;
496 Alarmer(int m, int h, bool d[7], bool isof = false)
497 {
498 changeSettings(m, h, d, isof);
499 }
500 void changeSettings(int m, int h, bool d[7], bool isof)
501 {
502 isBring = isof;
503 ms = m;
504 hs = h;
505 for (char i = 0; i < 7; i++)
506 {
507 ds[(int)i] = d[(int)i];
508 }
509 }
510 void get()
511 {
512 itoa(hs / 10, a, DEC);
513 itoa(hs % 10, b, DEC);
514 itoa(ms / 10, c, DEC);
515 itoa(ms % 10, d, DEC);
516 strcpy(e, "");
517 for (char i = 0; i < 7; i++)
518 {
519 if (ds[(int)i])
520 {
521 switch (i)
522 {
523 case 0:
524 strcpy(e + i, "M");
525 break;
526 case 1:
527 strcpy(e + i, "T");
528 break;
529 case 2:
530 strcpy(e + i, "W");
531 break;
532 case 3:
533 strcpy(e + i, "T");
534 break;
535 case 4:
536 strcpy(e + i, "F");
537 break;
538 case 5:
539 strcpy(e + i, "S");
540 break;
541 case 6:
542 strcpy(e + i, "S");
543 break;
544 }
545 }
546 else
547 {
548 strcpy(e + i, " ");
549 }
550 }
551 strcpy(text, a);
552 strcpy(text + 1, b);
553 strcpy(text + 2, ":");
554 strcpy(text + 3, c);
555 strcpy(text + 4, d);
556 strcpy(text + 5, " | ");
557 strcpy(text + 8, e);
558 strcpy(text + 15, " |");
559 }
560 int time(int m_real, int h_real, int d_real)
561 {
562 bool s = false;
563 for (char i = 0; i < 7; i++)
564 {
565 if (ds[(int)i])
566 {
567 s = true;
568 }
569 }
570 if (isBring && bringin_on && s)
571 {
572 for (char i = d_real; i < (d_real + 7); i++)
573 {
574 if (ds[(int)i % 7])
575 {
576 bliz_den = i % 7;
577 if (bliz_den < d_real)
578 {
579 bliz_den += 7;
580 }
581 break;
582 }
583 }
584 int out = (bliz_den - d_real) * 24 * 60;
585 out += (hs - hours) * 60;
586 out += ms - minets;
587 if (out <= 0)
588 {
589 char bliz_den_p = bliz_den;
590 bliz_den = 7;
591 for (char i = d_real; i < (d_real + 7); i++)
592 {
593 if (ds[(int)i % 7])
594 {
595 if ((i % 7) != bliz_den_p)
596 {
597 bliz_den = i % 7;
598 break;
599 }
600 }
601 }
602 }
603 out = (bliz_den - d_real) * 24 * 60;
604 out += (hs - hours) * 60;
605 out += ms - minets;
606 if (bliz_den == 45)
607 {
608 return INT16_MAX;
609 }
610 return out;
611 }
612 else
613 {
614 return INT16_MAX;
615 }
616 }
617 bool isBringing(int m_real, int h_real, int d_real)
618 {
619 if (isBring)
620 {
621 if (ds[d_real])
622 {
623 if (hs == h_real)
624 {
625 if (ms == m_real)
626 {
627 return true;
628 }
629 }
630 }
631 }
632 return false;
633 }
634 void turnOffBring()
635 {
636 bringin_on = false;
637 }
638 };
639 bool massiv[7] = {true, true, true, true,
640 true, true, true};
641 Alarmer alar[(signed char)4] = {Alarmer(0, 0, massiv),
642 Alarmer(0, 0, massiv),
643 Alarmer(0, 0, massiv),
644 Alarmer(0, 0, massiv)};
645 signed char mode1(bool perex)
646 {
647 signed char m = 1;
648 static bool settings = false;
649 static signed char mode_setting = 0;
650 static signed char selected = 0;
651 static signed char selected_day = 0;
652 if (perex)
653 {
654 settings = false;
655 ee_save1();
656 }
657 if (butt_settings.isClick())
658 {
659 if (wokeUpper())
660 {
661 if (settings)
662 {
663 if (mode_setting == 2)
664 {
665 if (selected_day == 6)
666 {
667 mode_setting = (mode_setting + 1) % 3;
668 selected_day = 0;
669 }
670 else
671 {
672 selected_day++;
673 }
674 }
675 else
676 {
677 mode_setting = (mode_setting + 1) % 3;
678 }
679 perex = true;
680 }
681 else
682 {
683 alar[selected].isBring = !alar[selected].isBring;
684 ee_save1();
685 perex = true;
686 }
687 }
688 }
689 if (butt_settings.isHolded())
690 {
691 if (wokeUpper())
692 {
693 if (!settings)
694 {
695 perex = true;
696 settings = true;
697 mode_setting = 0;
698 selected_day = 0;
699 }
700 else
701 {
702 perex = true;
703 settings = false;
704 ee_save1();
705 }
706 }
707 }
708 if (enc_show.isReady())
709 {
710 perex = true;
711 }
712 if (!settings)
713 {
714 if (enc.isLeft())
715 {
716 selected--;
717 enc_show.setTimeout(250 >> DELETEL);
718 }
719 if (enc.isRight())
720 {
721 selected++;
722 enc_show.setTimeout(250 >> DELETEL);
723 }
724 if (selected < 0)
725 {
726 selected = 0;
727 }
728 if (selected >= 4)
729 {
730 selected = 3;
731 }
732 //* display
733 if (perex)
734 {
735 lcd.clear();
736 for (char i = 0; i < 4; i++)
737 {
738 lcd.setCursor(0, i);
739 alar[(int)i].get();
740 lcd.print(alar[(int)i].text);
741 if (alar[(int)i].isBring)
742 {
743 lcd.print("+");
744 }
745 else
746 {
747 lcd.print("-");
748 }
749 if (selected == i)
750 {
751 lcd.setCursor(19, i);
752 lcd.write(5);
753 }
754 }
755 }
756 }
757 else
758 {
759 if (enc.isLeft())
760 {
761 if (mode_setting == 0)
762 {
763 alar[selected].hs--;
764 enc_show.setTimeout(250 >> DELETEL);
765 }
766 else if (mode_setting == 1)
767 {
768 alar[selected].ms--;
769 enc_show.setTimeout(250 >> DELETEL);
770 }
771 else if (mode_setting == 2)
772 {
773 alar[selected].ds[selected_day] = !alar[selected].ds[selected_day];
774 enc_show.setTimeout(250 >> DELETEL);
775 }
776 }
777 else if (enc.isRight())
778 {
779 if (mode_setting == 0)
780 {
781 alar[selected].hs++;
782 enc_show.setTimeout(250 >> DELETEL);
783 }
784 else if (mode_setting == 1)
785 {
786 alar[selected].ms++;
787 enc_show.setTimeout(250 >> DELETEL);
788 }
789 else if (mode_setting == 2)
790 {
791 alar[selected].ds[selected_day] = !alar[selected].ds[selected_day];
792 enc_show.setTimeout(250 >> DELETEL);
793 }
794 }
795 if (alar[selected].hs >= 24)
796 {
797 alar[selected].hs = alar[selected].hs % 24;
798 }
799 else if (alar[selected].hs < 0)
800 {
801 alar[selected].hs = 24 + alar[selected].hs;
802 }
803 if (alar[selected].ms >= 60)
804 {
805 alar[selected].ms = alar[selected].ms % 60;
806 }
807 else if (alar[selected].ms < 0)
808 {
809 alar[selected].ms = 60 + alar[selected].ms;
810 }
811 if (selected_day >= 7)
812 {
813 selected_day = 6;
814 }
815 else if (selected_day < 0)
816 {
817 selected_day = 0;
818 }
819 if (perex)
820 {
821 //* display
822 lcd.clear();
823 lcd.setCursor(0, 0);
824 lcd.print("ALARM ");
825 lcd.print(selected + 1);
826 lcd.print(" SETTINGS");
827 lcd.setCursor(0, 1);
828 alar[selected].get();
829 lcd.print(alar[selected].text);
830 lcd.setCursor(8, 3);
831 lcd.print("MTWTFSS");
832 if (mode_setting == 0)
833 {
834 lcd.setCursor(0, 2);
835 lcd.write(4);
836 lcd.write(4);
837 }
838 else if (mode_setting == 1)
839 {
840 lcd.setCursor(3, 2);
841 lcd.write(4);
842 lcd.write(4);
843 }
844 else if (mode_setting == 2)
845 {
846 lcd.setCursor(8 + selected_day, 2);
847 lcd.write(4);
848 }
849 }
850 }
851 return m;
852 }

Связаться
Выделить
Выделите фрагменты страницы, относящиеся к вашему сообщению
Скрыть сведения
Скрыть всю личную информацию
Отмена