Components and supplies
Ultrasonic Sensor - HC-SR04
ULN2803A relay driver IC
SD card reader/writer
BD 139 Transistor
Pam 8403 amplifier
DFPlayer - A Mini MP3 Player
CD 4504
LM7805 Voltage regulator
Raspberry Pi Pico
4 x 8x8 Dot Matrix with MAX7219
DS1307 RTC module
TSOP1838 Infrared Sensor
4 Digit 7 Segment Common Anode Display
AMS1117 3.3V power supply module
1 inch Common Anode seven segment LED display
Apps and platforms
Arduino IDE
Arduino IDE 1.8
Project description
Code
CLOCK 1
ARDUINO CODE FOR CLOCK 1
1/* ************************************************************* 2 3UPDATED ON 01 june 23 4 5 6*/ 7//************************************************************* 8#include "RTClib.h" 9#include<Wire.h> 10#include <IRremote.hpp> 11#define RECEIVER_PIN 9 12RTC_DS1307 RTC; 13IRrecv receiver(RECEIVER_PIN); 14int digit1 = 16; 15int digit2 = 13; 16int digit3 = 11; 17int digit4 = 12; 18int digit6 = 17; 19int digit5 = 18; 20int segA = 7; 21int segB = 8; 22int segC = 2; 23int segD = 5; 24int segE = 21; 25int segF = 6; 26int segG = 3; 27int Dot = 10; 28int Mode; 29int aset; 30int dtt2; 31int setmode = 0; 32int dispoff_flag = 1; 33int keyx; 34int count = 0; 35int keysum; 36int keysum1; 37int keyvalid; 38int set_mode = 0; 39int time_set = 0 ; 40int alm_set; 41int charshow1; 42int charshow2; 43int char1; 44int char2 ; 45int char3; 46int char4; 47int char5; 48int char6; 49int Hrset; 50int oldHrset; 51int Ulset; 52int oldUlset; 53int timp2; 54int typeset = 0; 55int tempC =0; 56int Alm_P_off; 57int pc=0; 58int kn=0; 59int enterkeypress=0; 60int retnkey=0; 61int date_set; 62int Snset; 63int oldSnset; 64int old_Alm_P_off; 65unsigned long key_value = 0; 66bool datesetflag; 67bool set_start =0; 68bool power_on=1; 69String receive_string; 70void ShowNumber(int ); 71void displaychar(int , int); 72void Light_HR_MIN(int); 73void displaysecond(int ); 74void IRR(int , int); 75void big_char(int , int ,int , int ); 76void sentdata2pico(String); 77void recivdatapico(void); 78void DT_SET( int , int ); 79 80 81//==================================================================================================== 82void setup() { 83 Serial.begin(9600); 84 Serial1.begin( 9600); 85 Wire1.setSDA(14); 86 Wire1.setSCL(15); 87 Wire.setSDA(0); 88 Wire.setSCL(1); 89 RTC.begin(&Wire1) ; 90 Wire1.begin(); 91 Wire.begin(); 92 RTC.begin(&Wire1); 93 DateTime now = RTC.now(); 94 //RTC.adjust(DateTime(__DATE__, __TIME__));// for setting clock remove 95 //after setting clock again put // on the line and upload once more 96 pinMode(segA, OUTPUT); 97 pinMode(segB, OUTPUT); 98 pinMode(segC, OUTPUT); 99 pinMode(segD, OUTPUT); 100 pinMode(segE, OUTPUT); 101 pinMode(segF, OUTPUT); 102 pinMode(segG, OUTPUT); 103 pinMode(Dot, OUTPUT); 104 pinMode(digit1, OUTPUT); 105 pinMode(digit2, OUTPUT); 106 pinMode(digit3, OUTPUT); 107 pinMode(digit4, OUTPUT); 108 pinMode(digit5, OUTPUT); 109 pinMode(digit6, OUTPUT); 110 digitalWrite(Dot, LOW); 111 digitalWrite(5, LOW); 112// ..................WELCOME DISPLAY------------------------------------- 113 114for (int p =3 ; p > 0 ; p--) { 115 for (int i =80 ; i > 0 ; i--) { 116 117 big_char(10,19,11,1) ; 118 displaychar(33,33) ; 119 } 120 ShowNumber(10); 121 delay(300); 122 } 123 IrReceiver.begin(9); // enable the receiver 124//--------auto syncronising on power on--------------------------------------------------------------- 125 126 127} 128//========================================END OF SETUP================================================ 129 130void loop() { // ==========================VOID LOOP================================================== 131DateTime now = RTC.now(); 132if (power_on==1){ 133 delay (2000); 134recivdatapico(); 135oldHrset=Hrset; 136oldSnset=Snset; 137old_Alm_P_off=Alm_P_off; 138power_on =0 ; 139} 140 141//====================================DISPLAY OFF FUNCTION.=========================================== 142 if ( dispoff_flag == 0) { 143 digitalWrite(digit1, LOW); 144 digitalWrite(digit2, LOW); 145 digitalWrite(digit3, LOW); 146 digitalWrite(digit4, LOW); 147 digitalWrite(digit5, LOW); 148 digitalWrite(digit6, LOW); 149 digitalWrite(segA, LOW); 150 digitalWrite(segB, LOW); 151 digitalWrite(segD, LOW); 152 digitalWrite(segC, LOW); 153 digitalWrite(segE, LOW); 154 digitalWrite(segF, LOW); 155 digitalWrite(segG, LOW); 156 digitalWrite(Dot, LOW); 157 158 } 159else{ 160 161//=================================TEMPERATURE DISPLAY =========================================== 162 163 if (Mode == 4) 164 { 165 for (int i = 8 ; i > 0 ; i--) { 166 Light_HR_MIN(tempC); 167 displaychar(16 , 15) ; 168 } 169} 170 else{} 171 172 //---------------------------------------ALARM PERMANET OFF------------------------------------------ 173 174if (Mode ==8){ 175if(set_start == 0){ 176 sentdata2pico("a") ; 177} 178 set_start=1; 179 if (Alm_P_off == 0) char4=17; 180 else char4=18; 181 for (int i = 8 ; i > 0 ; i--) { 182 big_char(11,12,0,char4) ; 183 ShowNumber(10); 184 } 185} 186else{} 187 if (Mode ==8 && enterkeypress ==1) { 188 Mode =0; 189 enterkeypress =0; 190 set_start=0; 191 old_Alm_P_off=Alm_P_off; 192 pc=0; 193 String ap; 194 ap = "N"+String(Alm_P_off); 195 sentdata2pico(ap); 196 delay(100); 197 } 198 else{} 199 200//--------------------------------------HOUR CHIME SETTING ------------------------------------------- 201 202if (Mode ==9){ 203if(set_start == 0){ 204 sentdata2pico("h") ; 205} 206set_start=1; 207 208 if (Hrset == 1){ 209 char1=16; 210 char2=19; 211 char3=26; 212 char4=26; 213 char5=0; 214 char6=18; 215 } 216 if (Hrset == 2){ 217 char1=26; 218 char2=26; 219 char3=27; 220 char4=12; 221 char5=0; 222 char6=18; 223 224 } 225 if (Hrset == 3){ 226 char1=29; 227 char2=30; 228 char3=13; 229 char4=28; 230 char5=0; 231 char6=18; 232 } 233 if (Hrset == 4){ 234 char1=16; 235 char2=19; 236 char3=26; 237 char4=26; 238 char5=18; 239 char6=13; 240 } 241 if (Hrset == 5){ 242 char1=26; 243 char2=26; 244 char3=27; 245 char4=12; 246 char5=18; 247 char6=13; 248 } 249if (Hrset == 6){ 250 char1=29; 251 char2=30; 252 char3=13; 253 char4=28; 254 char5=18; 255 char6=13; 256 } 257if (Hrset == 7){ 258 char1=29; 259 char2=30; 260 char3=13; 261 char4=28; 262 char5=0; 263 char6=17; 264 } 265 for (int i = 8 ; i > 0 ; i--) { 266 big_char(char1,char2,char3,char4) ; 267 ShowNumber(10); 268 displaychar(char6,char5); 269 } 270} 271else{} 272 if (Mode ==9 && enterkeypress ==1) { 273 Mode=0; 274 enterkeypress =0; 275 oldHrset=Hrset; 276set_start=0; 277String hp = "R"+String(Hrset); 278 279sentdata2pico(hp); 280delay(100); 281 282 283 284kn=0; 285 286 } 287 else{} 288//--------------------VOLUME SETTING----------------------------------------------------------------- 289 if (Mode ==12){ 290if(set_start == 0){ 291 sentdata2pico("s") ; 292} 293set_start=1; 294 295 if (Snset>= 33 || Snset== 0) Snset=0; 296 else{} 297 for (int i = 8 ; i > 0 ; i--) { 298 big_char(14,18,24,26) ; 299 ShowNumber(10); 300 displaysecond(Snset); 301 } 302} 303 else{} 304 if (Mode ==12 && enterkeypress ==1) { 305 Mode=0; 306 enterkeypress =0; 307 oldSnset=Snset; 308 set_start=0; 309String hq = "S"+String(Snset); 310sentdata2pico(hq); 311kn=0; 312 } 313 else{} 314 315//------- sound volume end--------------------------------------------------------------------------- 316 317//=================================REAL TIME DISPLAY================================================= 318 319 if (Mode == 0) { 320 DateTime now = RTC.now(); 321 int tim = (now.hour()); 322 if (tim > 12) { 323 tim = tim - 12; 324 } 325 else; 326 if (tim == 0) { 327 tim = 12; 328 } 329 else; 330 int timp = (tim * 100 + now.minute()); 331 int timp1 = now.second(); 332 timp2 = (now.hour() + now.minute()); 333// For Digits display 334 for (int i = 2 335 ; i > 0 ; i--) { 336 Light_HR_MIN(timp); 337 displaysecond(timp1); 338 } 339 } 340 else {} 341} 342 343// ---------------end of sync tine every hour--------------------------------------------------------- 344//----------------------------------------------------------------------------------------------------- 345 //===============================CHECKING REMOTE PESSING============================================ 346 347 if (IrReceiver.decode()) { 348//Serial.println("KEY RESULT"); 349//Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); 350 351//=================================TEMPERATURE DISPLAY KEY PRESSED================================== 352 if (IrReceiver.decodedIRData.decodedRawData == 0xEC13FF00 ) { 353 Mode = 4; 354recivdatapico(); 355delay(200); 356//timesync("t"); 357 } 358 else{ 359 receiver.resume(); 360 } 361 362//==================date display key pressed========================================================= 363 364 if (IrReceiver.decodedIRData.decodedRawData == 0xEA15FF00 ) { 365datesetflag=0; 366if(set_start == 0){ 367 //Serial.println("printing d"); 368 sentdata2pico("d") ; 369} 370set_start=1; 371 DateTime now = RTC.now(); 372 int hj = (now.day()*100)+now.month(); 373 for (int i = 2 ; i > 0 ; i--) { 374 Light_HR_MIN(hj); 375 displaysecond(now.year()%100); 376 } 377 Mode =15; 378 sentdata2pico("U"); 379 typeset = 3; 380 setmode = 1; 381 int ya=now.day(); 382 int yb=now.month(); 383 int yc= now.year(); 384 int datest = ((ya*10000)+(yb* 100) + (yc%100)); 385 receiver.resume(); 386 DT_SET (datest , 3); 387 if (datesetflag ==1){ 388 receiver.resume(); 389 int hr=now.hour(); 390 int mnn = now.minute(); 391 int scs = now.second(); 392 int mnt = (date_set/100)%100; 393 int dy = date_set/ 10000; 394 int yr = 2000+(date_set%100); 395 396RTC.adjust(DateTime(yr,mnt,dy, hr, mnn, scs)); 397//---- date set for sending to other board--------------------------------------------------------- 398String hr1= String (hr); 399if(hr/10 ==0) hr1=("0"+hr1); 400if(hr ==0) hr1=("00"); 401String mn1= String(mnn); 402if(mnn/10 ==0) mn1=("0"+mn1); 403if(mnn ==0) mn1=("00"); 404String mnt1=String(mnt); 405if(mnt/10 ==0) mnt1=("0"+mnt1); 406if(mnt ==0) mnt1=("00"); 407String dy1=String(dy); 408if(dy/10 ==0) dy1=("0"+dy1); 409String yr1=String(yr); 410 int scc = now.second(); 411String scc1=String(scc); 412if(scc/10 ==0) scc1=("0"+scc1); 413if(scc ==0) scc1=("00"); 414 415String tk = "T"+yr1+mnt1+dy1+hr1+mn1+scc1 ; 416sentdata2pico("Z"); 417sentdata2pico(tk); 418//sentdata2pico("Z"); 419delay(100); 420 421datesetflag=0; 422Mode = 0; 423 set_start=0; 424 } 425else{ 426 receiver.resume(); 427 } 428 } 429//=============================================RETURN KEY PRESSED===================================== 430 if (IrReceiver.decodedIRData.decodedRawData == 0xEB14FF00 ) { 431 432 typeset = 0; 433 Mode = 0; 434 enterkeypress ==0; 435 Alm_P_off =old_Alm_P_off; 436 Hrset=oldHrset; 437 Snset=oldSnset; 438 kn=0; 439 pc=0; 440 set_start=0; 441 retnkey == 1; 442 } 443 //=================================ENTER KEY PRESSED================================================= 444 if (IrReceiver.decodedIRData.decodedRawData == 0xF00FFF00 ) enterkeypress=1; 445 else enterkeypress=0; 446 447 //=========================ALRM PERMANENT OFF key pressed=========================================== 448 449 if (IrReceiver.decodedIRData.decodedRawData == 0xF906FF00) { 450 Mode=8; 451 Alm_P_off = abs(Alm_P_off - 1); 452 if(pc==0) Alm_P_off = old_Alm_P_off ; 453 else{} 454 pc= pc+1; 455 delay(500); 456 } 457 else{} 458 459 //=========================HOUR CHIME mode KEY PRESSED============================================= 460 461 if (IrReceiver.decodedIRData.decodedRawData == 0xF10EFF00 ) { 462 Mode=9; 463 kn=kn+1; 464 Hrset = Hrset+1; 465 if(Hrset>=8)Hrset=1; 466 else{} 467 if (kn ==1) 468 {Hrset=oldHrset; 469 } 470 } 471 else{} 472 473//==========================ALARM SET KEY PRESSED===================================================== 474 if (IrReceiver.decodedIRData.decodedRawData == 0xF807FF00 ) { 475 476 if(set_start == 0){ 477 // Serial.println("printing n"); 478 sentdata2pico("n") ; 479} 480 set_start=1; 481 typeset = 1; 482 setmode = 0; 483 Mode = 1; 484 keysum1 = alm_set; 485 int oldalm=alm_set; 486 receiver.resume(); 487 IRR( keysum1 , 1); 488 alm_set = keysum1; 489 if (retnkey == 1){ 490 alm_set=oldalm; 491 retnkey == 0; 492} 493else{ 494 String al; 495 al = "A"+ String(alm_set); 496 sentdata2pico(al); 497 aset = 6; 498 typeset = 0; 499 Mode == 0; 500 } 501 } 502 503// ==============TIME SET KEY PRESSED============================================================ 504 505 if (IrReceiver.decodedIRData.decodedRawData == 0xED12FF00 ) { 506 if(set_start == 0){ 507 sentdata2pico("t"); 508 delay(100); 509} 510 set_start=1; 511 typeset = 2; 512 setmode = 1; 513 Mode = 1; 514 DateTime now = RTC.now(); 515 dtt2 = now.hour() * 100 + now.minute(); 516 int Y1=now.year(); 517 int M1 = now.month(); 518 int D1 =now.day(); 519 receiver.resume(); 520 IRR( dtt2 , 2); 521//--------------------- 522if (retnkey ==1){ 523 Mode = 0; 524 enterkeypress ==0; 525 retnkey == 0; 526} 527 if (enterkeypress ==1){ 528 receiver.resume(); 529 int newtime = keysum1; 530 int h1 = newtime / 100; 531 int m1 = newtime % 100; 532 //int s1=now.second(); 533 set_start=0; 534 535//======================== 536 String hh1= String (h1); 537 if(h1/10 ==0) hh1=("0"+hh1); 538 if(h1 ==0) hh1=("00"); 539 String mm1= String (m1); 540 if(m1/10 ==0) mm1=("0"+mm1); 541 if(m1 ==0) mm1=("00"); 542 String YY1= String(Y1); 543 String MM1= String(M1); 544 if(M1/10 ==0) MM1=("0"+MM1); 545 if(M1 ==0) MM1=("00"); 546 String DD1= String(D1); 547 if(D1/10 ==0) DD1=("0"+DD1); 548 if(D1 ==0) DD1=("00"); 549 int s1 = now.second(); 550 String ss1=String(s1); 551 if(s1/10 ==0) ss1=("0"+ss1); 552 if(s1 ==0) ss1=("00"); 553 String tr3 = "T"+ YY1+MM1+DD1+hh1+mm1+ss1; 554 RTC.adjust(DateTime(Y1,M1,D1, h1, m1, s1)); 555 set_start=0; 556 enterkeypress=0; 557 // sentdata2pico("Z"); 558 sentdata2pico(tr3); 559 // sentdata2pico("Z"); 560 delay(100); 561 } 562 else{} 563 } 564 565//=======================ALARM OFF KEY PRESSED=================================================== 566 567 if (IrReceiver.decodedIRData.decodedRawData == 0xE916FF00 ) { 568 sentdata2pico("O"); 569 } 570 else { 571 receiver.resume(); 572 } 573 574//====================Sound set KEY PRESSED======================================================= 575 576 if (IrReceiver.decodedIRData.decodedRawData == 0xF609FF00 ) { 577 delay(100); 578 Mode=12; 579 kn=kn+1; 580 Snset = Snset+3; 581 if(Snset>=33)Snset=0; 582 else{} 583 if (kn ==1) 584 {Snset=oldSnset; 585} 586 else{} 587 } 588 589 //============DISPLAY ON/ OFF) KEY PRESSED===================================================== 590 591 if (IrReceiver.decodedIRData.decodedRawData == 0xF30CFF00 ) { 592 dispoff_flag = abs(dispoff_flag - 1); 593 String di; 594 di = "V"+String(dispoff_flag); 595 sentdata2pico("Z0"); 596 sentdata2pico(di); 597 delay(100); 598 } 599 else { 600 receiver.resume(); 601 } 602 } 603} 604//================================END OD REMOTE KEY PRESS CHECK=================================== 605 606//==========================END OF MAIN LOOP VOID()================================================ 607 608 609//=============================SUB PROGRAMMES======================================================= 610 611 612 void IRR( int keysum , int typeset ) { 613 while (typeset != 0) { 614 if (typeset == 1) { 615 for (int i = 8 ; i > 0 ; i--) { 616 617 Light_HR_MIN(keysum); 618 displaychar(12 , 11) ; 619 Light_HR_MIN(keysum); 620 } 621 } 622 else {} 623 624 if (typeset == 2) { 625 for (int i = 8 ; i > 0 ; i--) { 626 Light_HR_MIN(keysum); 627 displaychar(13 , 14) ; 628 Light_HR_MIN(keysum); 629 } 630 } 631 else {} 632 633 if (IrReceiver.decode()) { 634 635 switch (IrReceiver.decodedIRData.decodedRawData) { 636 637 case 0xEB14FF00 ://------------------------------RETURN KEY PRESSED--------------------------- 638 typeset = 0; 639 Mode = 0; 640 retnkey=1; 641 set_start=0; 642 enterkeypress=0; 643 break; 644 645//----------------------------------------------------------------------------------------------------- 646 647 case 0xF00FFF00 : // -----------------------PRESSING ENTER KEY---------------------------------- 648 649 if ( keysum / 10 == 0 && keysum >= 60 ) { 650 count = 0; 651 keysum = 0; 652 keyvalid = 0; 653 set_start=0; 654 enterkeypress=1; 655 } 656 else {} 657 658 if ( keysum / 100 == 0 && keysum >= 60) { 659 count = 0; 660 keysum = 0; 661 keyvalid = 0; 662 } 663 else {} 664 if ( keysum / 100 == 0 && keysum / 1000 == 0 && keysum % 100 >= 60 ) { 665 count = 0; 666 keysum = 0; 667 keyvalid = 0; 668 } 669 else {} 670 671 if ( keysum / 10000 == 0 && keysum % 100 >= 60 ) { 672 count = 0; 673 keysum = 0; 674 keyvalid = 0; 675 } 676 else { } 677 if (keyvalid == 1) { 678 typeset = 0; 679 Mode = 0; 680 retnkey =0; 681 enterkeypress=1; 682 } 683 else {} 684 break ; 685//------------------------- 686 case 0xEE11FF00: //........KEY 1......... 687 keyx = 1; 688 keysum = keysum * 10 + keyx; 689 count = count + 1; 690 break; 691 692 case 0xEE01FF00: //........KEY 1......... 693 keyx = 1; 694 keysum = keysum * 10 + keyx; 695 count = count + 1; 696 break; 697 698 case 0xF708FF00: //........KEY 2..... 699 keyx = 2; 700 count = count + 1; 701 keysum = keysum * 10 + keyx; 702 break; 703 704case 0xFF10EF: //........KEY 2..... 705 keyx = 2; 706 count = count + 1; 707 keysum = keysum * 10 + keyx; 708 break; 709 710 711 case 0xEF10FF00: //........KEY 3 .... 712 keyx = 3; 713 count = count + 1; 714 keysum = keysum * 10 + keyx; 715 break; 716 717case 0xFF08F7: //........KEY 3 .... 718 keyx = 3; 719 count = count + 1; 720 keysum = keysum * 10 + keyx; 721 break; 722 723case 0xFF00FF00: //........KEY 4..... 724 keyx = 4; 725 count = count + 1; 726 keysum = keysum * 10 + keyx; 727 break ; 728 729 case 0xFF00FF: //........KEY 4..... 730 keyx = 4; 731 count = count + 1; 732 keysum = keysum * 10 + keyx; 733 break ; 734 735 case 0xFE01FF00: //........KEY 5..... 736 keyx = 5; 737 count = count + 1; 738 keysum = keysum * 10 + keyx; 739 break ; 740 case 0xFF807F: //........KEY 5..... 741 keyx = 5; 742 count = count + 1; 743 keysum = keysum * 10 + keyx; 744 break ; 745 746 case 0xFD02FF00: //........KEY 6..... 747 keyx = 6; 748 count = count + 1; 749 keysum = keysum * 10 + keyx; 750 break ; 751 752 case 0xFF40BF: //........KEY 6..... 753 keyx = 6; 754 count = count + 1; 755 keysum = keysum * 10 + keyx; 756 break ; 757 758case 0xFC03FF00: //........KEY 7..... 759 keyx = 7; 760 count = count + 1; 761 keysum = keysum * 10 + keyx; 762 break ; 763 764case 0xFFC03F: //........KEY 7..... 765 keyx = 7; 766 count = count + 1; 767 keysum = keysum * 10 + keyx; 768 break ; 769 770case 0xFB04FF00: //........KEY 8..... 771 keyx = 8; 772 count = count + 1; 773 keysum = keysum * 10 + keyx; 774 break ; 775case 0xFF20DF: //........KEY 8..... 776 keyx = 8; 777 count = count + 1; 778 keysum = keysum * 10 + keyx; 779 break ; 780 781case 0xFA05FF00: //........KEY 9..... 782 keyx = 9; 783 count = count + 1; 784 keysum = keysum * 10 + keyx; 785 break ; 786 787case 0xFFA05F: //........KEY 9..... 788 keyx = 9; 789 count = count + 1; 790 keysum = keysum * 10 + keyx; 791 break ; 792 793case 0xF50AFF00: //........KEY 0..... 794 keyx = 0; 795 count = count + 1; 796 keysum = keysum * 10 + keyx; 797 break ; 798 799 case 0xFF50AF: //........KEY 0..... 800 keyx = 0; 801 count = count + 1; 802 keysum = keysum * 10 + keyx; 803 break ; 804 } 805 //-------------------------------------------------------------------------------------------------- 806 if (count >= 5) { 807 count = 0; 808 keysum = 0; 809 } 810 else {} 811 812 if (keysum >= 2400) { 813 keysum = 0; 814 count = 0; 815 } 816 else {} 817 818 if (keysum <= 0) { 819 keysum = 0; 820 count = 0; 821 } 822 else {} 823 824 key_value = IrReceiver.decodedIRData.decodedRawData; 825 keyvalid = 1; 826 keysum1 = keysum; 827 828 if (typeset == 1) { 829 alm_set = keysum; 830 } 831 else {} 832 if (typeset == 2) { 833 time_set = keysum; 834 } 835 else {} 836 delay(50); 837 receiver.resume(); 838 } 839 } 840 } 841 //================================================================================================== 842 void Light_HR_MIN(int toDisplay) { 843 #define BRIGHTNESS 1000 844 #define DIGIT_ON HIGH 845 #define DIGIT_OFF LOW 846 int hrr = toDisplay / 100; 847 if (Mode == 1) 848 { digitalWrite(digit5, LOW); 849 digitalWrite(digit6, LOW); 850 } 851 else {} 852 853 for (int digit = 4 ; digit > 0 ; digit--) { 854 switch (digit) { 855 856 case 1: 857 if (hrr < 10 && hrr != 0 ) 858 { 859 digitalWrite(digit1, DIGIT_OFF); 860 } 861 else { 862 digitalWrite(digit1, DIGIT_ON); 863 } 864 break; 865 case 2: 866 digitalWrite(digit2, DIGIT_ON); 867 break; 868 case 3: 869 digitalWrite(digit3, DIGIT_ON); 870 break; 871 case 4: 872 digitalWrite(digit4, DIGIT_ON); 873 break; 874 } 875 ShowNumber(toDisplay % 10); 876 toDisplay /= 10; 877 delayMicroseconds(BRIGHTNESS); 878 ShowNumber(10); 879 //Turn off all digits 880 digitalWrite(digit1, DIGIT_OFF); 881 digitalWrite(digit2, DIGIT_OFF); 882 digitalWrite(digit3, DIGIT_OFF); 883 digitalWrite(digit4, DIGIT_OFF); 884 } 885 } 886 887 //================================================================================================== 888 void ShowNumber(int numberToDisplay) { 889 890#define SEGMENT_ON HIGH 891#define SEGMENT_OFF LOW 892 893 switch (numberToDisplay) { 894 case 0: 895 digitalWrite(segA, SEGMENT_ON); 896 digitalWrite(segB, SEGMENT_ON); 897 digitalWrite(segC, SEGMENT_ON); 898 digitalWrite(segD, SEGMENT_ON); 899 digitalWrite(segE, SEGMENT_ON); 900 digitalWrite(segF, SEGMENT_ON); 901 digitalWrite(segG, SEGMENT_OFF); 902 903 break; 904 case 1: 905 digitalWrite(segA, SEGMENT_OFF); 906 digitalWrite(segB, SEGMENT_ON); 907 digitalWrite(segC, SEGMENT_ON); 908 digitalWrite(segD, SEGMENT_OFF); 909 digitalWrite(segE, SEGMENT_OFF); 910 digitalWrite(segF, SEGMENT_OFF); 911 digitalWrite(segG, SEGMENT_OFF); 912 break; 913 case 2: 914 digitalWrite(segA, SEGMENT_ON); 915 digitalWrite(segB, SEGMENT_ON); 916 digitalWrite(segC, SEGMENT_OFF); 917 digitalWrite(segD, SEGMENT_ON); 918 digitalWrite(segE, SEGMENT_ON); 919 digitalWrite(segF, SEGMENT_OFF); 920 digitalWrite(segG, SEGMENT_ON); 921 break; 922 case 3: 923 digitalWrite(segA, SEGMENT_ON); 924 digitalWrite(segB, SEGMENT_ON); 925 digitalWrite(segC, SEGMENT_ON); 926 digitalWrite(segD, SEGMENT_ON); 927 digitalWrite(segE, SEGMENT_OFF); 928 digitalWrite(segF, SEGMENT_OFF); 929 digitalWrite(segG, SEGMENT_ON); 930 break; 931 case 4: 932 digitalWrite(segA, SEGMENT_OFF); 933 digitalWrite(segB, SEGMENT_ON); 934 digitalWrite(segC, SEGMENT_ON); 935 digitalWrite(segD, SEGMENT_OFF); 936 digitalWrite(segE, SEGMENT_OFF); 937 digitalWrite(segF, SEGMENT_ON); 938 digitalWrite(segG, SEGMENT_ON); 939 break; 940 case 5: 941 digitalWrite(segA, SEGMENT_ON); 942 digitalWrite(segB, SEGMENT_OFF); 943 digitalWrite(segC, SEGMENT_ON); 944 digitalWrite(segD, SEGMENT_ON); 945 digitalWrite(segE, SEGMENT_OFF); 946 digitalWrite(segF, SEGMENT_ON); 947 digitalWrite(segG, SEGMENT_ON); 948 break; 949 case 6: 950 digitalWrite(segA, SEGMENT_ON); 951 digitalWrite(segB, SEGMENT_OFF); 952 digitalWrite(segC, SEGMENT_ON); 953 digitalWrite(segD, SEGMENT_ON); 954 digitalWrite(segE, SEGMENT_ON); 955 digitalWrite(segF, SEGMENT_ON); 956 digitalWrite(segG, SEGMENT_ON); 957 break; 958 case 7: 959 digitalWrite(segA, SEGMENT_ON); 960 digitalWrite(segB, SEGMENT_ON); 961 digitalWrite(segC, SEGMENT_ON); 962 digitalWrite(segD, SEGMENT_OFF); 963 digitalWrite(segE, SEGMENT_OFF); 964 digitalWrite(segF, SEGMENT_OFF); 965 digitalWrite(segG, SEGMENT_OFF); 966 break; 967 case 8: 968 digitalWrite(segA, SEGMENT_ON); 969 digitalWrite(segB, SEGMENT_ON); 970 digitalWrite(segC, SEGMENT_ON); 971 digitalWrite(segD, SEGMENT_ON); 972 digitalWrite(segE, SEGMENT_ON); 973 digitalWrite(segF, SEGMENT_ON); 974 digitalWrite(segG, SEGMENT_ON); 975 break; 976 case 9: 977 digitalWrite(segA, SEGMENT_ON); 978 digitalWrite(segB, SEGMENT_ON); 979 digitalWrite(segC, SEGMENT_ON); 980 digitalWrite(segD, SEGMENT_ON); 981 digitalWrite(segE, SEGMENT_OFF); 982 digitalWrite(segF, SEGMENT_ON); 983 digitalWrite(segG, SEGMENT_ON); 984 break; 985 case 10: //... FOR ALL DISP OFF 986 digitalWrite(segA, SEGMENT_OFF); 987 digitalWrite(segB, SEGMENT_OFF); 988 digitalWrite(segC, SEGMENT_OFF); 989 digitalWrite(segD, SEGMENT_OFF); 990 digitalWrite(segE, SEGMENT_OFF); 991 digitalWrite(segF, SEGMENT_OFF); 992 digitalWrite(segG, SEGMENT_OFF); 993 break; 994 995 case 11: //------FOR SHOWING A 996 digitalWrite(segA, SEGMENT_ON); 997 digitalWrite(segB, SEGMENT_ON); 998 digitalWrite(segC, SEGMENT_ON); 999 digitalWrite(segD, SEGMENT_OFF); 1000 digitalWrite(segE, SEGMENT_ON); 1001 digitalWrite(segF, SEGMENT_ON); 1002 digitalWrite(segG, SEGMENT_ON); 1003 break; 1004 1005 case 12: // ------FOR SHOWING L 1006 digitalWrite(segA, SEGMENT_OFF); 1007 digitalWrite(segB, SEGMENT_OFF); 1008 digitalWrite(segC, SEGMENT_OFF); 1009 digitalWrite(segD, SEGMENT_ON); 1010 digitalWrite(segE, SEGMENT_ON); 1011 digitalWrite(segF, SEGMENT_ON); 1012 digitalWrite(segG, SEGMENT_OFF); 1013 break; 1014 1015 case 13: //--- FOR SHOWING t 1016 digitalWrite(segA, SEGMENT_OFF); 1017 digitalWrite(segB, SEGMENT_OFF); 1018 digitalWrite(segC, SEGMENT_OFF); 1019 digitalWrite(segD, SEGMENT_ON); 1020 digitalWrite(segE, SEGMENT_ON); 1021 digitalWrite(segF, SEGMENT_ON); 1022 digitalWrite(segG, SEGMENT_ON); 1023 break; 1024 1025 case 14: //------FOR SHOWING S 1026 digitalWrite(segA, SEGMENT_ON); 1027 digitalWrite(segB, SEGMENT_OFF); 1028 digitalWrite(segC, SEGMENT_ON); 1029 digitalWrite(segD, SEGMENT_ON); 1030 digitalWrite(segE, SEGMENT_OFF); 1031 digitalWrite(segF, SEGMENT_ON); 1032 digitalWrite(segG, SEGMENT_ON); 1033 break; 1034 1035case 15: //------FOR SHOWING DEGREE SYMBOL 1036 digitalWrite(segA, SEGMENT_ON); 1037 digitalWrite(segB, SEGMENT_ON); 1038 digitalWrite(segC, SEGMENT_OFF); 1039 digitalWrite(segD, SEGMENT_OFF); 1040 digitalWrite(segE, SEGMENT_OFF); 1041 digitalWrite(segF, SEGMENT_ON); 1042 digitalWrite(segG, SEGMENT_ON); 1043 break; 1044case 16: //------FOR SHOWING C 1045 digitalWrite(segA, SEGMENT_ON); 1046 digitalWrite(segB, SEGMENT_OFF); 1047 digitalWrite(segC, SEGMENT_OFF); 1048 digitalWrite(segD, SEGMENT_ON); 1049 digitalWrite(segE, SEGMENT_ON); 1050 digitalWrite(segF, SEGMENT_ON); 1051 digitalWrite(segG, SEGMENT_OFF); 1052 break; 1053case 17: //------FOR SHOWING F 1054 digitalWrite(segA, SEGMENT_ON); 1055 digitalWrite(segB, SEGMENT_OFF); 1056 digitalWrite(segC, SEGMENT_OFF); 1057 digitalWrite(segD, SEGMENT_OFF); 1058 digitalWrite(segE, SEGMENT_ON); 1059 digitalWrite(segF, SEGMENT_ON); 1060 digitalWrite(segG, SEGMENT_ON); 1061 break; 1062 1063case 18: //------FOR SHOWING n 1064 digitalWrite(segA, SEGMENT_OFF); 1065 digitalWrite(segB, SEGMENT_OFF); 1066 digitalWrite(segC, SEGMENT_ON); 1067 digitalWrite(segD, SEGMENT_OFF); 1068 digitalWrite(segE, SEGMENT_ON); 1069 digitalWrite(segF, SEGMENT_OFF); 1070 digitalWrite(segG, SEGMENT_ON); 1071 break; 1072 1073case 19: //------FOR SHOWING H 1074 digitalWrite(segA, SEGMENT_OFF); 1075 digitalWrite(segB, SEGMENT_ON); 1076 digitalWrite(segC, SEGMENT_ON); 1077 digitalWrite(segD, SEGMENT_OFF); 1078 digitalWrite(segE, SEGMENT_ON); 1079 digitalWrite(segF, SEGMENT_ON); 1080 digitalWrite(segG, SEGMENT_ON); 1081 1082 break; 1083 1084case 20: //------FOR SHOWING G 1085 digitalWrite(segA, SEGMENT_ON); 1086 digitalWrite(segB, SEGMENT_OFF); 1087 digitalWrite(segC, SEGMENT_ON); 1088 digitalWrite(segD, SEGMENT_ON); 1089 digitalWrite(segE, SEGMENT_ON); 1090 digitalWrite(segF, SEGMENT_ON); 1091 digitalWrite(segG, SEGMENT_ON); 1092 break; 1093 1094case 21: //------FOR SHOWING SMALL O 1095 digitalWrite(segA, SEGMENT_OFF); 1096 digitalWrite(segB, SEGMENT_OFF); 1097 digitalWrite(segC, SEGMENT_ON); 1098 digitalWrite(segD, SEGMENT_ON); 1099 digitalWrite(segE, SEGMENT_ON); 1100 digitalWrite(segF, SEGMENT_OFF); 1101 digitalWrite(segG, SEGMENT_ON); 1102 break; 1103 1104 1105case 22: //------FOR SHOWING SMALL V 1106 digitalWrite(segA, SEGMENT_OFF); 1107 digitalWrite(segB, SEGMENT_OFF); 1108 digitalWrite(segC, SEGMENT_ON); 1109 digitalWrite(segD, SEGMENT_ON); 1110 digitalWrite(segE, SEGMENT_ON); 1111 digitalWrite(segF, SEGMENT_OFF); 1112 digitalWrite(segG, SEGMENT_OFF); 1113 break; 1114 1115case 23: //------FOR SHOWING SMALL i 1116 digitalWrite(segA, SEGMENT_OFF); 1117 digitalWrite(segB, SEGMENT_OFF); 1118 digitalWrite(segC, SEGMENT_ON); 1119 digitalWrite(segD, SEGMENT_OFF); 1120 digitalWrite(segE, SEGMENT_OFF); 1121 digitalWrite(segF, SEGMENT_OFF); 1122 digitalWrite(segG, SEGMENT_OFF); 1123 break; 1124 1125 1126case 24: //------FOR SHOWING SMALL d 1127 digitalWrite(segA, SEGMENT_OFF); 1128 digitalWrite(segB, SEGMENT_ON); 1129 digitalWrite(segC, SEGMENT_ON); 1130 digitalWrite(segD, SEGMENT_ON); 1131 digitalWrite(segE, SEGMENT_ON); 1132 digitalWrite(segF, SEGMENT_OFF); 1133 digitalWrite(segG, SEGMENT_ON); 1134 break; 1135 1136case 25: //------FOR SHOWING SMALL n 1137 digitalWrite(segA, SEGMENT_OFF); 1138 digitalWrite(segB, SEGMENT_OFF); 1139 digitalWrite(segC, SEGMENT_ON); 1140 digitalWrite(segD, SEGMENT_OFF); 1141 digitalWrite(segE, SEGMENT_ON); 1142 digitalWrite(segF, SEGMENT_OFF); 1143 digitalWrite(segG, SEGMENT_ON); 1144 break; 1145case 26: //------FOR SHOWING - 1146 digitalWrite(segA, SEGMENT_OFF); 1147 digitalWrite(segB, SEGMENT_OFF); 1148 digitalWrite(segC, SEGMENT_OFF); 1149 digitalWrite(segD, SEGMENT_OFF); 1150 digitalWrite(segE, SEGMENT_OFF); 1151 digitalWrite(segF, SEGMENT_OFF); 1152 digitalWrite(segG, SEGMENT_ON); 1153 break; 1154case 27: //------FOR SHOWING -U 1155 digitalWrite(segA, SEGMENT_OFF); 1156 digitalWrite(segB, SEGMENT_ON); 1157 digitalWrite(segC, SEGMENT_ON); 1158 digitalWrite(segD, SEGMENT_ON); 1159 digitalWrite(segE, SEGMENT_ON); 1160 digitalWrite(segF, SEGMENT_ON); 1161 digitalWrite(segG, SEGMENT_OFF); 1162 break; 1163case 28: //------FOR SHOWING -h 1164 digitalWrite(segA, SEGMENT_OFF); 1165 digitalWrite(segB, SEGMENT_OFF); 1166 digitalWrite(segC, SEGMENT_ON); 1167 digitalWrite(segD, SEGMENT_OFF); 1168 digitalWrite(segE, SEGMENT_ON); 1169 digitalWrite(segF, SEGMENT_ON); 1170 digitalWrite(segG, SEGMENT_ON); 1171 break; 1172case 29: //------FOR SHOWING -b 1173 digitalWrite(segA, SEGMENT_OFF); 1174 digitalWrite(segB, SEGMENT_OFF); 1175 digitalWrite(segC, SEGMENT_ON); 1176 digitalWrite(segD, SEGMENT_ON); 1177 digitalWrite(segE, SEGMENT_ON); 1178 digitalWrite(segF, SEGMENT_ON); 1179 digitalWrite(segG, SEGMENT_ON); 1180 break; 1181case 30: //------FOR SHOWING -SMALL o); 1182 digitalWrite(segA, SEGMENT_OFF); 1183 digitalWrite(segB, SEGMENT_OFF); 1184 digitalWrite(segC, SEGMENT_ON); 1185 digitalWrite(segD, SEGMENT_ON); 1186 digitalWrite(segE, SEGMENT_ON); 1187 digitalWrite(segF, SEGMENT_OFF); 1188 digitalWrite(segG, SEGMENT_ON); 1189 1190 break; 1191case 31: //------FOR SHOWING -SMALL j); 1192 digitalWrite(segA, SEGMENT_OFF); 1193 digitalWrite(segB, SEGMENT_ON); 1194 digitalWrite(segC, SEGMENT_ON); 1195 digitalWrite(segD, SEGMENT_ON); 1196 digitalWrite(segE, SEGMENT_OFF); 1197 digitalWrite(segF, SEGMENT_OFF); 1198 digitalWrite(segG, SEGMENT_OFF); 1199 break; 1200case 32: //------FOR SHOWING -SMALL b); 1201 digitalWrite(segA, SEGMENT_OFF); 1202 digitalWrite(segB, SEGMENT_OFF); 1203 digitalWrite(segC, SEGMENT_ON); 1204 digitalWrite(segD, SEGMENT_ON); 1205 digitalWrite(segE, SEGMENT_ON); 1206 digitalWrite(segF, SEGMENT_ON); 1207 digitalWrite(segG, SEGMENT_ON); 1208break; 1209case 33: //------FOR SHOWING underscore _); 1210 digitalWrite(segA, SEGMENT_OFF); 1211 digitalWrite(segB, SEGMENT_OFF); 1212 digitalWrite(segC, SEGMENT_OFF); 1213 digitalWrite(segD, SEGMENT_ON); 1214 digitalWrite(segE, SEGMENT_OFF); 1215 digitalWrite(segF, SEGMENT_OFF); 1216 digitalWrite(segG, SEGMENT_OFF); 1217 } 1218 } 1219 1220 //=================================================================================================- 1221 void displaysecond(int sec) { 1222#define BRIGHTNESS 1000 1223#define BRIGHTNESS1 400 1224 1225#define DIGIT_ON HIGH 1226#define DIGIT_OFF LOW 1227 1228 digitalWrite(digit1, DIGIT_OFF); 1229 digitalWrite(digit2, DIGIT_OFF); 1230 digitalWrite(digit3, DIGIT_OFF); 1231 digitalWrite(digit4, DIGIT_OFF); 1232 digitalWrite(digit6, DIGIT_OFF); 1233 digitalWrite(digit5, DIGIT_OFF); 1234 int yy = sec / 10; 1235 int aa = sec % 10; 1236 if (sec % 2 == 0 ) { 1237 digitalWrite(Dot, HIGH); 1238 delayMicroseconds(BRIGHTNESS1); 1239 } 1240 else; 1241 { digitalWrite(Dot, LOW); 1242 delayMicroseconds(BRIGHTNESS1); 1243 } 1244 1245 digitalWrite(digit5, DIGIT_OFF); 1246 digitalWrite(digit6, DIGIT_ON); 1247 ShowNumber(aa ); 1248 delayMicroseconds(BRIGHTNESS); 1249 ShowNumber(10); 1250 digitalWrite(digit6, DIGIT_OFF); 1251 digitalWrite(digit5, DIGIT_ON); 1252 ShowNumber(yy); 1253 delayMicroseconds(BRIGHTNESS); 1254 ShowNumber(10); 1255 digitalWrite(digit6, DIGIT_OFF); 1256 digitalWrite(digit5, DIGIT_OFF); 1257 } 1258 1259 //================================================================================================== 1260 1261 void displaychar(int charshow1 , int charshow2) { 1262#define BRIGHTNESS 2000 1263#define BRIGHTNESS1 400 1264#define DIGIT_ON HIGH 1265#define DIGIT_OFF LOW 1266 1267 digitalWrite(digit1, DIGIT_OFF); 1268 digitalWrite(digit2, DIGIT_OFF); 1269 digitalWrite(digit3, DIGIT_OFF); 1270 digitalWrite(digit4, DIGIT_OFF); 1271 digitalWrite(digit6, DIGIT_OFF); 1272 digitalWrite(digit5, DIGIT_ON); 1273 ShowNumber(charshow2); 1274 delayMicroseconds(BRIGHTNESS); 1275 ShowNumber(10); 1276 digitalWrite(digit5, DIGIT_OFF); 1277 digitalWrite(digit6, DIGIT_ON); 1278 ShowNumber(charshow1 ); 1279 delayMicroseconds(BRIGHTNESS); 1280 digitalWrite(digit6, DIGIT_OFF); 1281 digitalWrite(digit5, DIGIT_OFF); 1282 ShowNumber(10); 1283 } 1284//==================================================================================================== 1285 void big_char(int char1 , int char2,int char3 , int char4) { 1286#define BRIGHTNESS 2000 1287#define BRIGHTNESS1 400 1288#define DIGIT_ON HIGH 1289#define DIGIT_OFF LOW 1290 digitalWrite(digit6, DIGIT_OFF); 1291 digitalWrite(digit5, DIGIT_OFF); 1292 digitalWrite(digit1, DIGIT_ON); 1293 digitalWrite(digit2, DIGIT_OFF); 1294 digitalWrite(digit3, DIGIT_OFF); 1295 digitalWrite(digit4, DIGIT_OFF); 1296 ShowNumber(char1); 1297 delayMicroseconds(BRIGHTNESS); 1298 ShowNumber(10); 1299 digitalWrite(digit1, DIGIT_OFF); 1300 digitalWrite(digit2, DIGIT_ON); 1301 ShowNumber(char2 ); 1302 delayMicroseconds(BRIGHTNESS); 1303 ShowNumber(10); 1304 digitalWrite(digit2, DIGIT_OFF); 1305 digitalWrite(digit3, DIGIT_ON); 1306 ShowNumber(char3 ); 1307 delayMicroseconds(BRIGHTNESS); 1308 ShowNumber(10); 1309 digitalWrite(digit3, DIGIT_OFF); 1310 digitalWrite(digit4, DIGIT_ON); 1311 ShowNumber(char4 ); 1312 delayMicroseconds(BRIGHTNESS); 1313 ShowNumber(10); 1314 digitalWrite(digit4, DIGIT_OFF); 1315 1316 ShowNumber(10); 1317 } 1318//============== DATE SET ======================================================================== 1319 1320void DT_SET( int keysum , int typeset ) { 1321if(set_start == 0){ 1322 //Serial.println("printing d"); 1323 sentdata2pico("d") ; 1324} 1325set_start=1; 1326keyvalid=1; 1327while (typeset != 0) { 1328 for (int i = 8 ; i > 0 ; i--) { 1329 Light_HR_MIN(keysum/100); 1330 displaysecond(keysum%100) ; 1331 Light_HR_MIN(keysum/100); 1332 } 1333 if (IrReceiver.decode()) { 1334 switch (IrReceiver.decodedIRData.decodedRawData) { 1335 1336 case 0xEB14FF00 ://------------------------------RETURN KEY PRESSED--------------------------- 1337 typeset = 0; 1338 Mode = 0; 1339 retnkey=1; 1340 set_start=0; 1341 break; 1342 1343 case 0xF00FFF00 : // -----------------------PRESSING ENTER KEY---------------------------------- 1344 1345 if ( keysum %100 <= 10 || keysum%100 >=51 ){ 1346 count = 0; 1347 keysum = 0; 1348 keyvalid = 0; 1349 } 1350 if ( ((keysum / 100)%100) < 0 || ((keysum / 100)%100) >=13) { 1351 count = 0; 1352 keysum = 0; 1353 keyvalid = 0; 1354 } 1355 if ( (keysum / 10000 < 0)|| (keysum / 10000 >=31) ) { 1356 count = 0; 1357 keysum = 0; 1358 keyvalid = 0; 1359 } 1360 1361 if (keyvalid == 1) { 1362 typeset = 0; 1363 Mode = 0; 1364 retnkey =0; 1365 datesetflag =1; 1366 date_set=keysum; 1367 set_start=0; 1368 return; 1369 } 1370 break ; 1371 //-------------------------------------------------------------- 1372 case 0xEE11FF00: //........KEY 1......... 1373 keyx = 1; 1374 keysum = keysum * 10 + keyx; 1375 count = count + 1; 1376 break; 1377 1378 case 0xF708FF00: //........KEY 2..... 1379 keyx = 2; 1380 count = count + 1; 1381 keysum = keysum * 10 + keyx; 1382 break; 1383 1384 case 0xEF10FF00: //........KEY 3 .... 1385 keyx = 3; 1386 count = count + 1; 1387 keysum = keysum * 10 + keyx; 1388 break; 1389 1390 case 0xFF00FF00: //........KEY 4..... 1391 keyx = 4; 1392 count = count + 1; 1393 keysum = keysum * 10 + keyx; 1394 break ; 1395 1396 case 0xFE01FF00: //........KEY 5..... 1397 keyx = 5; 1398 count = count + 1; 1399 keysum = keysum * 10 + keyx; 1400 break ; 1401 1402 case 0xFD02FF00: //........KEY 6..... 1403 keyx = 6; 1404 count = count + 1; 1405 keysum = keysum * 10 + keyx; 1406 break ; 1407 1408 case 0xFC03FF00: //........KEY 7..... 1409 keyx = 7; 1410 count = count + 1; 1411 keysum = keysum * 10 + keyx; 1412 break ; 1413 1414 case 0xFB04FF00: //........KEY 8..... 1415 keyx = 8; 1416 count = count + 1; 1417 keysum = keysum * 10 + keyx; 1418 break ; 1419 1420 case 0xFA05FF00: //........KEY 9..... 1421 keyx = 9; 1422 count = count + 1; 1423 keysum = keysum * 10 + keyx; 1424 break ; 1425 1426 case 0xF50AFF00: //........KEY 0..... 1427 keyx = 0; 1428 count = count + 1; 1429 keysum = keysum * 10 + keyx; 1430 break ; 1431 } 1432 //----------------------------------------------------- 1433 1434 if (keysum >= 311251) { 1435 keysum = 0; 1436 count = 0; 1437 keyvalid=0; 1438 } 1439 keyvalid = 1; 1440 keysum1 = keysum; 1441 delay(50); 1442 receiver.resume(); 1443 1444 }// while typeset0 1445 } 1446 return; 1447} 1448 1449//====================HAND SHAKING======================================= 1450void sentdata2pico(String dsent){ 1451Wire.begin(); 1452delay(1000); 1453char dat[dsent.length()]; 1454 dsent.toCharArray(dat,dsent.length()+1); 1455Wire.beginTransmission(8); 1456Wire.write(dat); 1457Wire.endTransmission(); 1458Wire1.begin(); 1459 RTC.begin(&Wire1); 1460return; 1461} 1462//========RECEIVING DATA FROM SLAVE CLOCK====================================== 1463void recivdatapico(void){ 1464 DateTime now = RTC.now(); 1465Wire.begin(); 1466Serial.begin(); 1467String g=""; 1468char c[11]; 1469Wire.requestFrom(8, 26, true); /* request & read data of size 12 from slave */ 1470 1471for (int jj= 0 ; jj<=26 ; jj++){ 1472c[jj] = Wire.read(); 1473g=g+c[jj]; 1474} 1475String g2=g.substring(0,14); 1476g=g.substring(14); 1477alm_set=(g.substring(0,4)).toInt(); 1478Alm_P_off=(g.substring(4,5)).toInt(); 1479Hrset=(g.substring(5,6)).toInt(); 1480String g1=g.substring(6); 1481Snset=(g1.substring(0,2)).toInt(); 1482tempC=(g1.substring(2,6)).toInt(); 1483//========= 1484 1485if(power_on==1){ 1486int tmm=(g2.toInt()); 1487int yrs=(g2.substring(0,4)).toInt(); 1488int mms=(g2.substring(4,6)).toInt(); 1489int dys=(g2.substring(6,8)).toInt(); 1490int hrs=(g2.substring(8,10)).toInt(); 1491int mns=(g2.substring(10,12)).toInt(); 1492int ses=(g2.substring(12)).toInt(); 1493RTC.adjust(DateTime(yrs,mms,dys, hrs, mns, ses)); 1494delay(50); 1495} 1496//==================== 1497 return; 1498 1499} 1500//-------------------- end of hand shaking----------------------------------------------------------
CLOCK-2
c
ARDUINO CODE FOR CLOCK 2
1/*linked all variabled received over i2c 2UPDATED ON 4 JULY 23 3*/ 4 #include <SPI.h> 5 #include <RP2040_SD.h> 6 #include <MD_Parola.h> 7 #include <MD_MAX72xx.h> 8 #include <Wire.h> 9 #include "NewPing.h" 10 #include "DHT.h" 11 #include <RTClib.h> 12 #include "DFRobotDFPlayerMini.h" 13 #define DHTPIN 11 14 #define DHTTYPE DHT11 15 #define MAX_DEVICES 8 16 #define CS_PIN 9 17 #define DATA_PIN 7 18 #define CLK_PIN 6 19 #define SOUND_VELOCITY 0.034 20 #define TRIGGER_PIN 22 21 #define ECHO_PIN 21 22 #define MAX_DISTANCE 400 23 #define HARDWARE_TYPE MD_MAX72XX::FC16_HW 24 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); 25 RTC_DS1307 rtc; 26 DHT dht(DHTPIN, DHTTYPE); 27 MD_MAX72XX *pM; 28 MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES); 29 DFRobotDFPlayerMini myDFPlayer; 30 void sdfilelines(void); 31 void sdsingleline(int); 32 void disptime(int); 33 void anim(void); 34 void mp3play(int , int, int); 35 void timespeak(void); 36 void mng_evg_song_play(int, int); 37 void checkstatus(void); 38 void ultrasound(void); 39 void sd_datastor(String); 40 void line1(void ); 41 void Temperature(void); 42//----------------------------------------- 43 int mrg_wish_hr = 4; int mrg_wish_min = 15; 44 int mngsong_hr = 6; int mngsong_min = 30; 45 int evgsong_hr = 18; int evgsong_min = 3; 46//------------------------------------------ 47 File myFile; 48 String displine; 49 String sdfile ; 50 String lin; 51 String lin1; 52 String spos; 53 String L; 54 String data_string; 55 String message1 = "Good Morning"; 56 String message2 = "Good After noon"; 57 String message3 = "Good Evening"; 58 String message4 = "Good Night"; 59 String message; 60 char care; 61 char R; 62 char song; 63 long duration; 64 bool ch_stat = 0; 65 bool hr_onoff; 66 bool ul_onoff; 67 bool lin_stop = 0; 68 float humid; 69 float heat; 70 float dist_cm; 71 int Alm_time = 06; 72 int chimeblk=0; 73 int alhr ; 74 int almn; 75 int I = 0 ; 76 int lineno; 77 int k; 78 int totline; 79 int mpos; 80 int ps[800]; 81 int dely = 1000; 82 int Tempr; 83 int randtotline; 84 int snd_block_start =22; int snd_block_end =4; 85 int rr = 1; 86//--variables for handshaking----- 87 int Disp_on; 88 int snoozon; 89 int Almoff = 0; 90 int ALM_time; 91 int Hr_status; 92 int Alm_Poff; 93 int Snd_vol; 94 int req_no=1; 95//--------------------------------------------------------------------------------- 96 void setup() 97 { 98 Wire1.setSDA(14); 99 Wire1.setSCL(15); 100 Wire.setSDA(12); 101 Wire.setSCL(13); 102 rtc.begin(&Wire1) ; 103 Wire.begin(8); 104 Wire1.begin(); 105 Wire.begin(8); 106 Wire.onReceive(receiveEvent); 107 Wire.onRequest(requestEvent); 108 Serial1.begin( 9600); 109 Serial.begin(9600); 110 dht.begin(); 111 pM = myDisplay.getGraphicObject(); 112 //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 113 myDisplay.begin(); 114 myDisplay.setIntensity(0); 115 myDisplay.setTextAlignment(PA_RIGHT); 116 myDisplay.setPause(1000); 117 myDisplay.setSpeed(100); 118 myDisplay.displayClear(); 119 Serial.begin(9600); 120 121 if (!SD.begin()) { 122 } 123 myFile = SD.open(sdfile); 124 mpos = 0; 125 pinMode(10, INPUT); 126 Serial1.begin(9600); 127 Serial.begin(9600); 128 myDFPlayer.begin(Serial1); 129 delay(1000); 130 if (!myDFPlayer.begin(Serial1)) { 131 } 132 myDFPlayer.start(); 133 delay(100); 134 sd_datastor("R" ) ; 135 alhr = ALM_time / 100; 136 almn = ALM_time % 100; 137 myDFPlayer.volume(Snd_vol); 138 myDFPlayer.playFolder(5, 1); 139 delay(100); 140 sdfile = "comments.txt"; 141 sdfilelines(); 142 randtotline = totline; 143 myDisplay.displayText("HAI..", PA_CENTER, 100, 1, PA_BLINDS); 144 while (myDisplay.displayAnimate() == false) { } 145 } 146//--------------------------------------------------------------------------------- 147 void loop() { 148 Temperature(); 149 Serial.begin(9600); 150 DateTime now = rtc.now(); 151 int hr = now.hour(); 152 int mn = now.minute(); 153 int scc = now.second(); 154 myDisplay.displayClear(); 155 myDFPlayer.volume(Snd_vol); 156 //--------------------------------------------------------------------------------- 157 if (hr >= 4 && hr <= 12)message = message1; 158 if (hr >= 13 && hr <= 16)message = message2; 159 if (hr >= 16 && hr <= 20)message = message3; 160 if (hr >= 20 && hr <= 23)message = message4; 161 if (hr >= 0 && hr < 4)message = message4; 162 checkstatus(); 163 164//---------------------------------------morng wish-start---------------------------- 165 if ( hr == mrg_wish_hr && mn == mrg_wish_min && scc <= 2) { 166 ch_stat = 1; 167 myDisplay.displayClear(); 168 myDFPlayer.volume(Snd_vol); 169 myDFPlayer.playFolder(5, 1); 170 delay(1000); 171 myDisplay.displayText("Hai Sobha Good Morning ...", PA_RIGHT, 100, 1, PA_SCROLL_LEFT); 172 while (myDisplay.displayAnimate() == false) { 173 } 174 ch_stat = 1; 175 } 176//------------------------------------morng wish end--------------------------------- 177 178//------------------------------------30 min and hour speak--------------------------- 179 if ( mn == 30 && scc <= 3 && hr_onoff==0 && chimeblk==0 ) { 180 ch_stat = 1; 181 myDisplay.displayClear(); 182 myDFPlayer.volume(Snd_vol); 183 myDFPlayer.playFolder(7, 2); 184 delay(1000); 185 for (int kh = 1 ; kh <= 2 ; kh++) { 186 myDisplay.displayText("HALF HOUR ", PA_CENTER, 100, 1, PA_BLINDS); 187 while (myDisplay.displayAnimate() == false) { 188 } 189 delay(1000); 190 } 191 timespeak(); 192 ch_stat = 0; 193 myDisplay.displayClear(); 194 } 195 else 196 {ch_stat = 0; } 197 //--------------------------------------------------------------------------------- 198 if ( mn == 0 && scc <= 3 && hr_onoff==0 && chimeblk==0) { 199 ch_stat = 1; 200 myDisplay.displayClear(); 201 myDFPlayer.volume(Snd_vol); 202 myDFPlayer.playFolder(7, 1); 203 delay(1000); 204 for (int hh = 1 ; hh <= 6 ; hh++) { 205 myDisplay.displayText("DING DING ", PA_CENTER, 100, 1, PA_BLINDS); 206 while (myDisplay.displayAnimate() == false) { 207 } 208 myDisplay.displayClear(); 209 delay(1500); 210 } 211 ch_stat = 0; 212 } 213 else { 214 ch_stat = 0; 215 } 216 217//--------------------------------------------------------------------------------- 218 if ( hr == alhr && mn == almn && scc <= 2 && Alm_Poff == 1) { 219 ch_stat = 1; 220 chimeblk=1; 221 myDisplay.displayClear(); 222 myDFPlayer.volume(30); 223 Almoff = 0; 224 myDFPlayer.playFolder(3, 1); 225 delay(1000); 226 myDisplay.displayText("ALARM ", PA_RIGHT, 100, 1, PA_SCROLL_LEFT); 227 while ((myDisplay.displayAnimate() == false) ||(Almoff == 0) ) { 228 checkstatus(); 229 } 230 delay(2000); 231 ch_stat = 1; 232 chimeblk=0; 233 } 234//-------------------------30 min and hour speak end------------------------------ 235//--------------------------morning and Evg song---------------------------------- 236 if ( hr == mngsong_hr && mn == mngsong_min && scc <= 2 ) { 237 ch_stat = 1; 238 chimeblk=1; 239 sdfile = "test.txt"; 240 myDFPlayer.volume(Snd_vol); 241 mng_evg_song_play(3, 1); 242 ch_stat = 0; 243 chimeblk=0; 244 Almoff == 0; 245 } 246 247 if ( hr == evgsong_hr && mn == evgsong_min && scc <= 2 ) { 248 ch_stat = 1; 249 chimeblk=1; 250 sdfile = "test.txt"; 251 myDFPlayer.volume(Snd_vol); 252 mng_evg_song_play(3, 1); 253 ch_stat = 0; 254 chimeblk=0; 255 Almoff == 0; 256 } 257 258//---------------- --- End of morning and Evg song-------------------------------- 259 260//------------------------------normal time --------------------------------------- 261 checkstatus(); 262 if (ch_stat == 0) { 263 myDisplay.displayClear(); 264 int msglength = (message.length() + 1); 265 char mssg[msglength]; 266 message.toCharArray(mssg, msglength); 267 myDisplay.displayScroll(mssg, PA_RIGHT, PA_SCROLL_LEFT, 80); 268 while (myDisplay.displayAnimate() == false) { 269 ultrasound(); 270 checkstatus(); 271 if (ch_stat == 1)return; 272 } 273//-------------------Temperature Display----------------------------------------- 274 myDisplay.displayClear(); 275 String tmp = "Temp: " + String(heat) + " 'C" + " Humd: " + String(humid) + " %" ; 276 int tmp_length = (tmp.length() + 1); 277 char tmpr[tmp_length]; 278 tmp.toCharArray(tmpr, tmp_length); 279 myDisplay.displayScroll(tmpr, PA_RIGHT, PA_SCROLL_LEFT, 80); 280 while (myDisplay.displayAnimate() == false) { 281 ultrasound(); 282 checkstatus(); 283 if (ch_stat == 1)return; 284 } 285//--------------------------------------------------------------------------------- 286 myDisplay.displayClear(); 287 disptime(1); 288 checkstatus(); 289 } 290 ultrasound(); 291 } 292//-------------------END OF MAIN LOOP---------------------------------------------- 293 294//-------------------SUB PROGRAMS-------------------------------------------------- 295 void anim(void ) { 296 Serial.begin(9600); 297 int displength = displine.length() - 1; 298 char dispa[displength]; 299 displine.toCharArray(dispa, displength); 300 while (myDisplay.displayAnimate()) { 301 myDisplay.displayText(dispa, PA_RIGHT, 100, 1, PA_SCROLL_LEFT); 302 } 303 while (myDisplay.displayAnimate() == false) { 304 } 305 while (myDisplay.displayAnimate()) { 306 myDisplay.displayText(" ", PA_RIGHT, 40, 1, PA_SCROLL_LEFT); 307 } 308 while (myDisplay.displayAnimate() == false) { 309 } 310 311 myDisplay.displayClear(); 312 return; 313} 314//--------------------------------------------------------------------------------- 315 void sdsingleline(int lineno) { // To Read a single line from the opened file on SD card 316 myFile = SD.open(sdfile); 317 myFile.seek(ps[lineno]); 318 L = ""; 319 while (myFile.available()) { 320 R = myFile.read(); 321 L += R; 322 if ( R == '\n') { 323 displine = L; 324 return; 325 } 326 } 327 } 328//--------------------------------------------------------------------------------- 329 void sdfilelines(void){ // to find the total no of lines in the opened text file 330 int x = 2; 331 char rline; 332 int y = 0; 333 ps[1] = 0; 334 myFile = SD.open(sdfile); 335 while (myFile.available()) { 336 rline = myFile.read(); 337 y = y + 1; 338 if (rline == '\n') { 339 ps[x] = myFile.position() ; 340 x = x + 1; 341 y = 0; 342 } 343 } 344 totline = x - 1; 345 myFile.close(); 346 return; 347 } 348//--------------------------------------------------------------------------------- 349 void disptime(int tipe) { // to diplay Real time on Parala display 350 DateTime now = rtc.now(); 351 char time_format[] = " hh:mm:ss AP"; 352 char date_format[] = " DDD DD MMM YY"; 353 char time_format2[] = " hh:mm AP"; 354 if (tipe == 1) { 355 String apm; 356 int h1=now.hour(); 357 int m1=now.minute(); 358 int s1=now.second()+3; 359 if(s1>=60){ 360 s1=0; 361 m1=m1+1; 362 } 363 if(m1>=60){ 364 m1=0; 365 h1=h1+1; 366 } 367 368 if(h1 >= 12)apm=":PM"; 369 else{ 370 apm= ":AM"; 371 } 372 if(h1 >= 12)h1=h1-12; 373 if(h1 == 0)h1=12; 374 String hh1= String (h1); 375 if(h1/10 ==0) hh1=("0"+hh1); 376 if(h1 ==0) hh1=("00"); 377 String mm1= String (m1); 378 if(m1/10 ==0) mm1=("0"+mm1); 379 if(m1 ==0) mm1=("00"); 380 String ss1=String(s1); 381 if(s1/10 ==0) ss1=("0"+ss1); 382 if(s1 ==0) ss1=("00"); 383 String tr5 = hh1+":"+mm1+":"+ss1+apm; 384 int msgln = (tr5.length() + 1); 385 char msg[msgln]; 386 tr5.toCharArray(msg, msgln); 387 myDisplay.displayScroll(msg, PA_LEFT, PA_SCROLL_LEFT, 80); 388 while (myDisplay.displayAnimate() == false) { 389 ultrasound(); 390 checkstatus(); 391 if (ch_stat == 1) return; 392 } 393 myDisplay.displayClear(); 394 String up=now.toString(date_format); 395 up.toUpperCase(); 396 int upln = (up.length() + 1); 397 char upm[upln]; 398 up.toCharArray(upm, upln); 399 400 401 402 myDisplay.displayScroll(upm, PA_LEFT, PA_SCROLL_LEFT, 80); 403 while (myDisplay.displayAnimate() == false) { 404 ultrasound(); 405 checkstatus(); 406 if (ch_stat == 1) return; 407 } 408 myDisplay.displayClear(); 409 ch_stat == 1; 410 return; 411 } 412 if (tipe == 2) { 413 myDisplay.print(now.toString(time_format2)); 414 } 415 return; 416} 417//--------------------------------------------------------------------------------- 418 void mp3play(int fold , int playfileno , int timedely) { // to play Specifif Mp3 file on DF player 419 myDFPlayer.playFolder(fold, playfileno);; //now 420 delay(1000); 421 } 422//--------------------------------------------------------------------------------- 423 void timespeak( void) { // to play the time on MP3 player 424 DateTime now = rtc.now(); 425 int h = now.hour(); 426 int m = now.minute(); 427 int s = now.second(); 428 if (h >= 12) { 429 h = h - 12; 430 } 431 if (h == 0) { 432 h = 12; 433 } 434 myDFPlayer.playFolder(4, 1); //NOW TIME IS 435 delay(1000); 436 while (digitalRead(10) == LOW) { 437 } 438 myDFPlayer.playFolder(1, h); //hour 439 delay(dely); 440 while (digitalRead(10) == LOW) { 441 } 442 // myDFPlayer.playFolder(4, 2); //HOURS 443 //delay(dely); 444 // while (digitalRead(10) == LOW) { 445 // } 446 // myDFPlayer.playFolder(1, m); //min 447 //delay(dely); 448 //while (digitalRead(10) == LOW) { 449 // } 450 myDFPlayer.playFolder(4, 3); //min 451 delay(dely); 452 while (digitalRead(10) == LOW) { 453 } 454 return; 455} 456//--------------------------------------------------------------------------------- 457 void mng_evg_song_play(int fold , int fle) { // To play songs on Evening and morning at times specified 458 459 sdfilelines(); 460 int op = 1; 461 for (int line_count = 1 ; line_count <= totline; line_count++) { 462 if(Almoff == 1) { 463 sdfile = "comments.txt"; 464 sdfilelines(); 465 return; 466 } 467 if (op == 1) { 468 mp3play(fold, fle, 1000); 469 delay(1000); 470 } 471 op = op + 1; 472 sdsingleline(line_count); 473 anim(); 474// if ((line_count % 4) == 0) { 475// for (int t = 1; t <= 3; t ++) { 476// myDisplay.displayClear(); 477// disptime(2); 478// delay(1000); 479// myDisplay.displayClear(); 480// delay(500); 481// } 482// } 483// else {} 484 } 485 sdfile = "comments.txt"; 486 sdfilelines(); 487 return; 488 } 489//--------------------------------------------------------------------------------- 490 void checkstatus(void){ // To check the status of different sub systems 491 DateTime now = rtc.now(); 492 long int a1 = now.hour() * 3600 + now.minute() * 60 + now.second(); 493 long int a2 = now.minute() * 60 + now.second(); 494 long int mwish = mrg_wish_hr * 3600 + mrg_wish_min * 60; 495 long int msong = mngsong_hr * 3600 + mngsong_min * 60; 496 long int esong = evgsong_hr * 3600 + evgsong_min * 60; 497 long int alr = alhr * 3600 + almn * 60; 498 499 if (( a1 >= mwish - 3) && ( a1 <= mwish + 3) ) { // mrng wish 500 ch_stat = 1; return; } 501 502 if (( a1 >= msong - 3) && ( a1 <= msong + 3) ) { // morng song 503 ch_stat = 1; return; } 504 505 if (( a1 >= esong - 3) && ( a1 <= esong + 3) ) { // evening song 506 ch_stat = 1; return; } 507 508 if (( a2 >= 3597) || ( a2 <= 3)) { // full hour chime 509 ch_stat = 1; return; } 510 511 if ( (a2 >= 1797) && (a2 <= 1803) ) { // half hour chime 512 ch_stat = 1; return; } 513 514 if (( a1 >= alr - 3) && ( a1 <= alr + 3) ) { //alarm 515 ch_stat = 1; return; } 516 ch_stat = 0; 517 518//------------------------------------ 519 hr_onoff =1;ul_onoff =1; 520 if ((Hr_status==7) ){ 521 hr_onoff =1; 522 ul_onoff =1; 523 } 524 else {} 525 if ((Hr_status==1) || (Hr_status==3) ) hr_onoff =0; 526 else {} 527 if ((Hr_status==2) || (Hr_status==3) ) ul_onoff =0; 528 else {} 529 if ((( now.hour()>= snd_block_end)&&(now.hour()<=snd_block_start ))&& ( (Hr_status==4)|| (Hr_status==6)) ) { 530 hr_onoff =0; 531 } 532 else {} 533 if ((( now.hour()>=snd_block_end)&&(now.hour()<=snd_block_start ))&& ( (Hr_status==5)|| (Hr_status==6) ) ) { 534 ul_onoff =0; 535 } 536 else {} 537 return; 538 } 539//--------------------------------------------------------------------------------- 540 void ultrasound(void) { // to check/play ultra sound sensor 541 if(ul_onoff==0 && chimeblk==0){ 542 dist_cm=sonar.ping_cm(); 543 if ((dist_cm >= 2 ) && (dist_cm <= 250 )) { 544 ch_stat = 1; 545 myDisplay.displayClear(); 546 int rand_fileno = random(1, randtotline - 1); 547 sdsingleline(rand_fileno); 548 int displength = displine.length() - 1; 549 char dispa[displength]; 550 displine.toCharArray(dispa, displength); 551 myDisplay.displayText(dispa, PA_LEFT, 100, 1, PA_SCROLL_LEFT); 552 int dd = 1; 553 while (myDisplay.displayAnimate() == false) { 554 if (dd == 150){ 555 mp3play(10, rand_fileno, 1000); 556 delay(100); } 557 dd = dd + 1; } 558 ch_stat = 0; 559 } 560 else{} 561 } 562 else{}; 563 return; 564 } 565//--------------------------------------------------------------------------------- 566 void receiveEvent(int howMany) { // for actions to do when an event is received from master clock throuh I2C 567 Wire.begin(8); 568 String uc = ""; 569 String yt = ""; 570 String dt = ""; 571 String ti; 572 String req_type; 573 while (0 < Wire.available()) { 574 char c = Wire.read(); 575 uc = uc + c; 576 } 577 if (uc == "")uc = "Z0"; 578 req_type = uc.charAt(0); 579 uc = uc.substring(1); 580 ti =uc.charAt(0); 581 // if (uc == "Z")return; 582 583//======================================== 584 if (req_type == "N" ) { 585 //Serial.println ("ALM PER OFF "); 586 Alm_Poff = ti.toInt(); 587 sd_datastor("W" ) ; 588 } 589//========================================= 590 if (req_type == "R" ) { 591 //Serial.println (" hour chime set mode"); 592 Hr_status = ti.toInt(); 593 sd_datastor("W" ) ; 594 } 595//========================================== 596 if (req_type == "A" ) { 597 //Serial.println (" alarm set time"); 598 ALM_time = (uc.substring(0, 4)).toInt(); 599 alhr = ALM_time / 100; 600 almn = ALM_time % 100; 601 sd_datastor("W") ; 602 } 603//========================================== 604 if (req_type == "O" ) { 605 //Serial.println (" ALM OFF"); 606 Almoff = 1; 607 myDFPlayer.stop(); 608 lin1 = "ALM/PLR OFF"; 609 line1() ; 610 } 611 if (req_type == "S" ) { 612//Serial.println (" SOUND VOL"); 613 Snd_vol = (uc.substring(0, 2)).toInt(); 614 sd_datastor("W") ; 615 } 616//========================================= 617 if (req_type == "V" ) { 618 //Serial.println (" DISPLAY OFF"); 619 Disp_on = ti.toInt(); 620 if (Disp_on==0){ 621 pM->control(MD_MAX72XX::SHUTDOWN,1); } 622 else{ 623 pM->control(MD_MAX72XX::SHUTDOWN,0); 624 }} 625//========================================== 626 if (req_type == "t" ) { 627 lin1 = "SET TIME"; line1() ; } 628 629 if (req_type == "n" ) { 630 lin1 = "SET ALARM"; line1() ;} 631 632 if (req_type == "a" ) { 633 lin1 = "SET ALM-ON"; line1();} 634 635 if (req_type == "d" ) { 636 lin1 = "SET DATE";line1() ; } 637 638 if (req_type == "y" ) { 639 lin1 = "SYNC TIME";line1() ; } 640 641 if (req_type == "s" ) { 642 lin1 = "SET VOL"; line1() ; } 643 644 if (req_type == "h" ) { 645 lin1 = "SET CHIME";line1() ; } 646 647 if (req_type == "T" ) { 648 int ss = ((uc.substring(12)).toInt()) +6; 649 int mm = (uc.substring(10, 12)).toInt(); 650 if (ss >= 60 ){ 651 ss = ss - 60; 652 mm = mm + 1; } 653 int hh = (uc.substring(8,10)).toInt(); 654 int DD = (uc.substring(6, 8)).toInt(); 655 int MM = (uc.substring(4, 6)).toInt(); 656 int YY = (uc.substring(0, 4)).toInt(); 657 DateTime now = rtc.now(); 658 Wire1.begin(); 659 rtc.begin(&Wire1) ; 660 delay(50); 661 rtc.adjust(( DateTime(YY, MM, DD, hh, mm, ss))); 662 delay(500); 663 lin_stop = 0; 664 } 665 Wire1.begin(); 666 rtc.begin(&Wire1) ; 667 return; 668 } 669 670//--------------------------------------------------------------------------------- 671 void requestEvent() { // To read data from SD card and send to Master on power on 672 DateTime now = rtc.now(); 673 int Y1=now.year(); 674 int M1 = now.month(); 675 int D1 =now.day(); 676 int h1 =now.hour(); 677 int m1 =now.minute(); 678 String hh1= String (h1); 679 if(h1/10 ==0) hh1=("0"+hh1); 680 if(h1 ==0) hh1=("00"); 681 String mm1= String (m1); 682 if(m1/10 ==0) mm1=("0"+mm1); 683 if(m1 ==0) mm1=("00"); 684 String YY1= String(Y1); 685 String MM1= String(M1); 686 if(M1/10 ==0) MM1=("0"+MM1); 687 if(M1 ==0) MM1=("00"); 688 String DD1= String(D1); 689 if(D1/10 ==0) DD1=("0"+DD1); 690 if(D1 ==0) DD1=("00"); 691 int s1 = now.second(); 692 String ss1=String(s1); 693 if(s1/10 ==0) ss1=("0"+ss1); 694 if(s1 ==0) ss1=("00"); 695 String tr3 = YY1+MM1+DD1+hh1+mm1+ss1; 696 String a1 = String(ALM_time); 697 if ((ALM_time / 1000) <= 0)a1 = "0" + a1; 698 String a2 = String(Alm_Poff); 699 if (Alm_Poff == 0)a2 = "0"; 700 String a3 = String(Hr_status); 701 if ((Hr_status == 0))a3 = "0"; 702 String a4 = String(Snd_vol); 703 if ((Snd_vol / 10) <= 0)a4 = "0" + a4; 704 String t = String(Tempr); 705 String a5 = tr3+a1 + a2 + a3 + a4 + t; 706 char rs[25]; 707 a5.toCharArray(rs, 27); 708 Wire.begin(8); 709 Wire.write(rs, 26); 710 delay(100); 711 if(req_no==1) lin1 = "SEND DATA"; 712 else{ lin1 = "TEMPERATURE"; } 713 req_no=0; 714 line1() ; 715 return; 716 } 717//---------------- STORE DATA ON SD CARD------------------------------------------- 718 void sd_datastor(String rw ) { // For reading and Writing data on SD card 719 String la; 720 char ra; 721 if (rw == "R") { 722 myFile = SD.open("datastor.txt", FILE_READ); 723 la = ""; 724 while (myFile.available()) { 725 ra = myFile.read(); 726 la = la + ra; 727 } 728 data_string = la; 729 ALM_time = (la.substring(0, 4)).toInt(); 730 Alm_Poff = (la.substring(4, 5)).toInt(); 731 Hr_status = (la.substring(5, 6)).toInt(); 732 Snd_vol = (la.substring(6)).toInt(); 733 myFile.close(); 734 return; 735 } 736 if (rw == "W") { 737 SD.remove("datastor.txt"); 738 myFile = SD.open("datastor.txt", FILE_WRITE); 739 int d = ALM_time * 10000 + Alm_Poff * 1000 + Hr_status * 100 + Snd_vol; 740 String dd = String(d); 741 myFile.print(dd); 742 myFile.close(); 743 return; 744 }} 745//--------------------------------------------------------------------------------- 746 void line1(void ) { // for diplaying messages in single line on Parola 747 int lin1_length = lin1.length(); 748 char lin[lin1_length]; 749 lin1.toCharArray(lin, lin1_length + 1); 750 lin_stop = 1; 751 for (int kh = 1 ; kh <= 6 ; kh++) { 752 myDisplay.setTextAlignment(PA_CENTER); 753 myDisplay.print(lin ); 754 delay (200); 755 myDisplay.displayClear(); 756 delay (200); 757 } 758 return; 759 } 760//--------------------------------------------------------------------------------- 761 void Temperature(void) { // to Read Temperature and humidity from Sensor 762 delay(500); 763 humid = dht.readHumidity(); 764 heat = dht.readTemperature(); 765 Tempr = int(heat * 100); 766 return; 767 }
Downloadable files
CIRCUIT DIAGRAM OF CLOCK-1
f01a8e2f-8f41-437a-8dcd-a375d67d767a.jpg
CIRCUIT DIAGRAM OF CLOCK -2
04b530b2-f088-4e97-8d84-b34d17f1bbe1.jpg
I2C CONNECTION BET WEEN CLOCK-1 AND CLOCK-2
c75c3674-a518-4135-9bc0-a7125806bb8e.jpg
DIFFERENT COMPONENTS USED
file.None
Comments
Only logged in users can leave comments