Digital Clock with IR Remote Control using Arduino Nano R3
Digital Clock With Hour/Minute/Second /Temperature Display and Features Alarm/Snooze/Hour Chime with a full function IR Remote control
Components and supplies
Copper Clad Phenolic board 15 X 20 Cm
Suitable Enclosure
UM 66 music generator IC
1 inch Common Anode seven segment LED display
DS3231MPMB1 Peripheral Module
3 mm LED
2 inch small speaker 8 ohm , 0.5 w
Resistor 150 Ohm ¼ w
TSOP 1738 IR receiver
Continuous tone piezo buzzer 5V
Arduino Nano R3
1/2 inch Common Anode seven segment LED display
Female edge connector for mounting Arduino ( 40 pin)
Resistor 100 Ohm ¼ w
Resistor 220 Ohm ¼ w
IR Remote control unit
Apps and platforms
Arduino IDE
Project description
Code
Code For Digital Clock with IR remote
arduino
1//COMPLETE DIGITAL CLOCK WITH INFRARED REMOTE CONTROL BY AJITH KUMAR 2int digit1 = A3; 3int digit2 = 9; 4int digit3 = 10; 5int digit4 = 12; 6int digit6 = 13; 7int digit5 = A2; 8int segA = 4; 9int segB = 5; 10int segC = 8; 11int segD = 7; 12int segE = 6; 13int segF = 3; 14int segG = 2; 15int Dot = 1; 16int Hrchime = A1; 17int Almout = A0; 18int Disp_mode = 0; 19int aset; 20int aset1 = 3; // set value as 3 for first time retrival of alarm set 21int HCperiod = 12; // required time for hour chime in seconds 22int snoozperiod = 5; // required time to repeat alarm snooz in minutes 23int almperiod = 20; // maximum time of alarm ringing before auto off 24int dtt2; 25int snoozflag = 0; 26int snoozset = 0; 27int setmode = 0; 28int dispoff_flag = 1; 29int keyx; 30int count = 0; 31int keysum; 32int keysum1; 33int keyvalid; 34int set_mode = 0; 35int time_set = 0 ; 36int alm_set; 37int alm_set1; 38int charshow1; 39int charshow2; 40int timp2; 41int typeset = 0; 42int beep_onoff = 0; 43 44static unsigned int altim; 45static unsigned int altim1; 46unsigned long key_value = 0; 47 48 49//#include <Wire.h> 50#include "RTClib.h" 51#include <EEPROM.h> 52#include <IRremote.h> 53 54 55#define RECEIVER_PIN 11 56#define EEADDR 174 // Start location to write EEPROM data. 57#define EEADDR1 188 58RTC_DS3231 RTC; 59IRrecv receiver(RECEIVER_PIN); 60decode_results results; 61 62void ShowNumber(int ); 63void displaychar(int , int); 64void Light_HR_MIN(int); 65void displaysecond(int ); 66void IRR(int , int); 67void ALARMSTORE(int , int); 68 69//========================================================================================================== 70void setup() { 71 //Serial.begin(9600); 72 73 RTC.begin(); 74 DateTime now = RTC.now(); 75 //RTC.adjust(DateTime(__DATE__, __TIME__));// for setting clock remove // from this line and upload sketch 76 //after setting clock again put // on the line and upload once more 77 78 pinMode(segA, OUTPUT); 79 pinMode(segB, OUTPUT); 80 pinMode(segC, OUTPUT); 81 pinMode(segD, OUTPUT); 82 pinMode(segE, OUTPUT); 83 pinMode(segF, OUTPUT); 84 pinMode(segG, OUTPUT); 85 pinMode(Dot, OUTPUT); 86 pinMode(Hrchime, OUTPUT); 87 pinMode(digit1, OUTPUT); 88 pinMode(digit2, OUTPUT); 89 pinMode(digit3, OUTPUT); 90 pinMode(digit4, OUTPUT); 91 pinMode(digit5, OUTPUT); 92 pinMode(digit6, OUTPUT); 93 pinMode(Almout, OUTPUT); 94 digitalWrite(Almout, LOW); 95 digitalWrite(Hrchime, LOW); 96 digitalWrite(Almout, LOW); 97 98 99 // ------------------------------retrieving alarm set time from flash on power_on 100 101 int EEAddr = EEADDR; 102 int EEAddr1 = EEADDR1; 103 if (aset1 == 3 ) { 104 105 EEPROM.get(EEAddr , altim); EEAddr += sizeof(altim); 106 EEPROM.get(EEAddr1 , altim1); EEAddr1 += sizeof(altim1); 107 alm_set = altim1 * 100 + altim; 108 aset1 = 6; 109 aset = 7; 110 alm_set1 = alm_set; 111 } 112 else {} 113 114 //-------end of alrm set time reading from flash 115 116 receiver.enableIRIn(); // enable the receiver 117 int IRR(int); 118} 119 120//========================================END OF SETUP=================================== 121 122void loop() { // ==========================VOID LOOP===================================== 123 124 125 126 //====================================DISPLAY OFF FUNCTION.============================== 127 if ( dispoff_flag == 0) { 128 digitalWrite(digit1, LOW); 129 digitalWrite(digit2, LOW); 130 digitalWrite(digit3, LOW); 131 digitalWrite(digit4, LOW); 132 digitalWrite(digit5, LOW); 133 digitalWrite(digit6, LOW); 134 } 135 else { 136 137 //=================================TEMPERATURE DISPLAY ==================================== 138 139 if (Disp_mode == 4) { 140 float tempC = RTC.getTemperature(); 141 tempC = tempC * 100; 142 143 for (int i = 8 ; i > 0 ; i--) { 144 Light_HR_MIN(tempC); 145 displaychar(16 , 15) ; 146 } 147 148 } 149 else{} 150 151 //=================================REAL TIME DISPLAY======================================== 152 153 if (Disp_mode == 0) { 154 155 DateTime now = RTC.now(); 156 int tim = (now.hour()); 157 158 if (tim > 12) { 159 tim = tim - 12; 160 } 161 else; 162 if (tim == 0) { 163 tim = 12; 164 } 165 else; 166 int timp = (tim * 100 + now.minute()); 167 int timp1 = now.second(); 168 timp2 = (now.hour() + now.minute()); 169 170 171 // For Digits display 172 for (int i = 10 173 ; i > 0 ; i--) { 174 Light_HR_MIN(timp); 175 displaysecond(timp1); 176 } 177 } 178 179 else {} 180 181 } 182 //------------------------------------------------------------------------------------------- 183 //===============================CHECKING REMOTE PESSING===================================== 184 185 if (receiver.decode(&results)) { 186 187 //Serial.println("KEY RESULT"); // remove // of this line and next line to find the ir code of an unknown IR receiver 188 // Serial.println(results.value, HEX); 189 190 191 192 if (results.value == 0x1FE7887) { //=======TEMPERATURE DIDPLAY KEY PRESSED============== 193 Disp_mode = 4; 194 } 195 else 196 { receiver.resume(); 197 } 198 199//=============================================RETURN KEY PRESSED============================= 200 if (results.value == 0x1FE58A7) { 201 202 typeset = 0; 203 Disp_mode = 0; 204 } 205 //=========================================================================================== 206 207 if (results.value == 0x1FE40BF) { //=========== ALARM SET KEY PRESSED================== 208 typeset = 1; 209 setmode = 0; 210 //almblow=0; 211 Disp_mode = 1; 212 keysum1 = alm_set; 213 214 IRR( keysum1 , 1); 215 receiver.resume(); 216 alm_set = keysum1; 217 218 ALARMSTORE(alm_set , 1 ); 219 aset = 6; 220 221 } 222 else { 223 224 typeset = 0; 225 Disp_mode == 0; 226 } 227 228 //========================================================================================== 229 230 if (results.value == 0x1FEC03F) { // ============== TIME SET KEY PRESSED==================== 231 typeset = 2; 232 setmode = 1; 233 234 Disp_mode = 1; 235 DateTime now = RTC.now(); 236 dtt2 = now.hour() * 100 + now.minute(); 237 238 IRR( dtt2 , 2); 239 receiver.resume(); 240 241 //Serial.println(" "); 242 243 //Serial.print("TIME SET= "); 244 245 //Serial.println(keysum1); 246 int newtime = keysum1; 247 int h1 = newtime / 100; 248 int m1 = newtime % 100; 249 250 RTC.adjust(DateTime(2021, 1, 1, h1, m1, 0)); 251 252 } 253 else { 254 receiver.resume(); 255 } 256 //================================================================================================= 257 258 if (results.value == 0x1FEA05F) { //===============ALARM OFF KEY PRESSED========================== 259 260 Serial.print("ALM OFF "); 261 beep_onoff = 0; 262 snoozflag = 0; 263 //Serial.print(almblow); 264 } 265 else { 266 receiver.resume(); 267 } 268 269 //================================================================================================ 270 271 if (results.value == 0x1FE609F) { //============ SNOOZ ON KEY PRESSED============================= 272 delay(100); 273 // Serial.print("SNOOZ ON "); 274 275 snoozset = snoozset + snoozperiod; 276 snoozflag = 1; 277 Serial.print("snooz on "); 278 Serial.print(snoozset); 279 //digitalWrite(Almout, LOW); 280 beep_onoff = 0; 281 } 282 else { 283 receiver.resume(); 284 } 285 //=================================================================================================== 286 287 288 if (results.value == 0x1FE48B7) { //============OFF/ ON KEY (DISPLAY OFF) KEY PRESSED=============== 289 290 //Serial.print("display off OFF "); 291 //digitalWrite(Almout, LOW); 292 dispoff_flag = abs(dispoff_flag - 1); 293 294 delay(500); 295 } 296 297 else { 298 receiver.resume(); 299 } 300 } 301 302 //================================END OD REMOTE KEY PRESS CHECK======================================= 303 // ==================================ALARM CHECKING==================================================== 304 DateTime now = RTC.now(); 305 int xc = now.hour() * 100 + now.minute(); 306 int yc = now.second(); 307 308 if (xc == alm_set && yc == 1 ) { 309 //digitalWrite(Almout, HIGH); 310 snoozset = alm_set; 311 beep_onoff = 1; 312 313 } 314 else {} 315 316 if (snoozflag == 1) { 317 318 if (xc == snoozset && yc <= 1 ) { 319 320 beep_onoff = 1; 321 //digitalWrite(Almout, HIGH); 322 } 323 else {} 324 } 325 326 else {} 327 328 if ( xc == alm_set + almperiod ) { 329 //digitalWrite(Almout, LOW); 330 331 beep_onoff = 0; 332 snoozflag = 0; 333 } 334 else {} 335 336 //===============================Alarm Beeping =========================================================== 337 338 if (beep_onoff == 1 ) { 339 340 341 if (yc % 2 == 0) 342 digitalWrite(Almout, HIGH); 343 else 344 digitalWrite(Almout, LOW); 345 } 346 347 else 348 349 digitalWrite(Almout, LOW); 350 351 //========================================== hour chime=============================================== 352 353 354 int w1 = now.minute(); 355 int w2 = now.second(); 356 357 if (w1 == 0 && w2 <= HCperiod ) { 358 digitalWrite(Hrchime, HIGH); 359 } 360 else { 361 digitalWrite(Hrchime , LOW); 362 } 363 364 365 366 } //=================================END OF MAIN LOOP VOID()========================================== 367 368 //=============================SUB PROGRAMMES========================================================== 369 370 371 void IRR( int keysum , int typeset ) { 372 373 374 while (typeset != 0) { 375 376 if (typeset == 1) { 377 for (int i = 8 ; i > 0 ; i--) { 378 379 Light_HR_MIN(keysum); 380 displaychar(12 , 11) ; 381 Light_HR_MIN(keysum); 382 } 383 } 384 else {} 385 386 if (typeset == 2) { 387 for (int i = 8 ; i > 0 ; i--) { 388 Light_HR_MIN(keysum); 389 displaychar(13 , 14) ; 390 Light_HR_MIN(keysum); 391 } 392 } 393 else {} 394 395 if (receiver.decode(&results)) { 396 397 398 switch (results.value) { 399 400 case 0x1FE58A7://------------------------------RETURN KEY PRESSED-------------------------- 401 typeset = 0; 402 Disp_mode = 0; 403 break; 404 405 //----------------------------------------------------------------------------------------- 406 407 408 409 case 0x1FE20DF: // -----------------------PRESSING ENTER KEY---------------------------- 410 411 412 if ( keysum / 10 == 0 && keysum >= 60 ) { 413 count = 0; 414 keysum = 0; 415 keyvalid = 0; 416 } 417 else {} 418 419 if ( keysum / 100 == 0 && keysum >= 60) { 420 count = 0; 421 keysum = 0; 422 keyvalid = 0; 423 } 424 else {} 425 426 427 if ( keysum / 100 == 0 && keysum / 1000 == 0 && keysum % 100 >= 60 ) { 428 count = 0; 429 keysum = 0; 430 keyvalid = 0; 431 } 432 else {} 433 434 if ( keysum / 10000 == 0 && keysum % 100 >= 60 ) { 435 count = 0; 436 keysum = 0; 437 keyvalid = 0; 438 } 439 else { 440 } 441 if (keyvalid == 1) { 442 typeset = 0; 443 Disp_mode = 0; 444 } 445 else {} 446 447 break ; 448 449 case 0x1FE50AF: //..........KEY 1.... 450 keysum = keysum * 10 + keyx; 451 count = count + 1; 452 break; 453 case 0x1FED827: //........KEY 2..... 454 keyx = 2; 455 count = count + 1; 456 keysum = keysum * 10 + keyx; 457 break; 458 case 0x1FEF807: //........KEY 3 .... 459 keyx = 3; 460 count = count + 1; 461 keysum = keysum * 10 + keyx; 462 break; 463 case 0x1FE30CF: //........KEY 4..... 464 keyx = 4; 465 count = count + 1; 466 keysum = keysum * 10 + keyx; 467 break ; 468 case 0x1FEB04F: //........KEY 5..... 469 keyx = 5; 470 count = count + 1; 471 keysum = keysum * 10 + keyx; 472 break ; 473 case 0x1FE708F: //........KEY 6..... 474 keyx = 6; 475 count = count + 1; 476 keysum = keysum * 10 + keyx; 477 break ; 478 case 0x1FE00FF: //........KEY 7..... 479 keyx = 7; 480 count = count + 1; 481 keysum = keysum * 10 + keyx; 482 break ; 483 case 0x1FEF00F: //........KEY 8..... 484 keyx = 8; 485 count = count + 1; 486 keysum = keysum * 10 + keyx; 487 break ; 488 case 0x1FE9867: //........KEY 9..... 489 keyx = 9; 490 count = count + 1; 491 keysum = keysum * 10 + keyx; 492 break ; 493 case 0x1FEE01F: //........KEY 0..... 494 keyx = 0; 495 count = count + 1; 496 keysum = keysum * 10 + keyx; 497 break ; 498 499 } // 500 //-------------------------------------------------------------------------- 501 if (count >= 5) { 502 count = 0; 503 keysum = 0; 504 } 505 else {} 506 507 if (keysum >= 2400) { 508 keysum = 0; 509 count = 0; 510 } 511 else {} 512 513 if (keysum <= 0) { 514 keysum = 0; 515 count = 0; 516 } 517 else {} 518 519 key_value = results.value; 520 keyvalid = 1; 521 keysum1 = keysum; 522 523 if (typeset == 1) { 524 alm_set = keysum; 525 526 } 527 else {} 528 529 if (typeset == 2) { 530 time_set = keysum; 531 } 532 else {} 533 534 delay(50); 535 receiver.resume(); 536 } 537 } 538 } 539 //============================================================================================ 540 void Light_HR_MIN(int toDisplay) { 541#define BRIGHTNESS 1000 542#define DIGIT_ON HIGH 543#define DIGIT_OFF LOW 544 int hrr = toDisplay / 100; 545 546 if (Disp_mode == 1) 547 { digitalWrite(digit5, LOW); 548 digitalWrite(digit6, LOW); 549 } 550 else {} 551 552 for (int digit = 4 ; digit > 0 ; digit--) { 553 switch (digit) { 554 555 case 1: 556 if (hrr < 10 && hrr != 0 ) 557 { 558 digitalWrite(digit1, DIGIT_OFF); 559 } 560 else { 561 digitalWrite(digit1, DIGIT_ON); 562 } 563 break; 564 case 2: 565 digitalWrite(digit2, DIGIT_ON); 566 break; 567 case 3: 568 digitalWrite(digit3, DIGIT_ON); 569 break; 570 case 4: 571 digitalWrite(digit4, DIGIT_ON); 572 break; 573 } 574 575 ShowNumber(toDisplay % 10); 576 toDisplay /= 10; 577 delayMicroseconds(BRIGHTNESS); 578 ShowNumber(10); 579 //Turn off all digits 580 digitalWrite(digit1, DIGIT_OFF); 581 digitalWrite(digit2, DIGIT_OFF); 582 digitalWrite(digit3, DIGIT_OFF); 583 digitalWrite(digit4, DIGIT_OFF); 584 } 585 } 586 587 //======================================================================= 588 void ShowNumber(int numberToDisplay) { 589 590#define SEGMENT_ON LOW 591#define SEGMENT_OFF HIGH 592 593 switch (numberToDisplay) { 594 case 0: 595 596 digitalWrite(segA, SEGMENT_ON); 597 digitalWrite(segB, SEGMENT_ON); 598 digitalWrite(segC, SEGMENT_ON); 599 digitalWrite(segD, SEGMENT_ON); 600 digitalWrite(segE, SEGMENT_ON); 601 digitalWrite(segF, SEGMENT_ON); 602 digitalWrite(segG, SEGMENT_OFF); 603 604 break; 605 case 1: 606 digitalWrite(segA, SEGMENT_OFF); 607 digitalWrite(segB, SEGMENT_ON); 608 digitalWrite(segC, SEGMENT_ON); 609 digitalWrite(segD, SEGMENT_OFF); 610 digitalWrite(segE, SEGMENT_OFF); 611 digitalWrite(segF, SEGMENT_OFF); 612 digitalWrite(segG, SEGMENT_OFF); 613 break; 614 case 2: 615 digitalWrite(segA, SEGMENT_ON); 616 digitalWrite(segB, SEGMENT_ON); 617 digitalWrite(segC, SEGMENT_OFF); 618 digitalWrite(segD, SEGMENT_ON); 619 digitalWrite(segE, SEGMENT_ON); 620 digitalWrite(segF, SEGMENT_OFF); 621 digitalWrite(segG, SEGMENT_ON); 622 break; 623 case 3: 624 digitalWrite(segA, SEGMENT_ON); 625 digitalWrite(segB, SEGMENT_ON); 626 digitalWrite(segC, SEGMENT_ON); 627 digitalWrite(segD, SEGMENT_ON); 628 digitalWrite(segE, SEGMENT_OFF); 629 digitalWrite(segF, SEGMENT_OFF); 630 digitalWrite(segG, SEGMENT_ON); 631 break; 632 case 4: 633 digitalWrite(segA, SEGMENT_OFF); 634 digitalWrite(segB, SEGMENT_ON); 635 digitalWrite(segC, SEGMENT_ON); 636 digitalWrite(segD, SEGMENT_OFF); 637 digitalWrite(segE, SEGMENT_OFF); 638 digitalWrite(segF, SEGMENT_ON); 639 digitalWrite(segG, SEGMENT_ON); 640 break; 641 case 5: 642 digitalWrite(segA, SEGMENT_ON); 643 digitalWrite(segB, SEGMENT_OFF); 644 digitalWrite(segC, SEGMENT_ON); 645 digitalWrite(segD, SEGMENT_ON); 646 digitalWrite(segE, SEGMENT_OFF); 647 digitalWrite(segF, SEGMENT_ON); 648 digitalWrite(segG, SEGMENT_ON); 649 break; 650 case 6: 651 digitalWrite(segA, SEGMENT_ON); 652 digitalWrite(segB, SEGMENT_OFF); 653 digitalWrite(segC, SEGMENT_ON); 654 digitalWrite(segD, SEGMENT_ON); 655 digitalWrite(segE, SEGMENT_ON); 656 digitalWrite(segF, SEGMENT_ON); 657 digitalWrite(segG, SEGMENT_ON); 658 break; 659 case 7: 660 digitalWrite(segA, SEGMENT_ON); 661 digitalWrite(segB, SEGMENT_ON); 662 digitalWrite(segC, SEGMENT_ON); 663 digitalWrite(segD, SEGMENT_OFF); 664 digitalWrite(segE, SEGMENT_OFF); 665 digitalWrite(segF, SEGMENT_OFF); 666 digitalWrite(segG, SEGMENT_OFF); 667 break; 668 case 8: 669 digitalWrite(segA, SEGMENT_ON); 670 digitalWrite(segB, SEGMENT_ON); 671 digitalWrite(segC, SEGMENT_ON); 672 digitalWrite(segD, SEGMENT_ON); 673 digitalWrite(segE, SEGMENT_ON); 674 digitalWrite(segF, SEGMENT_ON); 675 digitalWrite(segG, SEGMENT_ON); 676 break; 677 case 9: 678 digitalWrite(segA, SEGMENT_ON); 679 digitalWrite(segB, SEGMENT_ON); 680 digitalWrite(segC, SEGMENT_ON); 681 digitalWrite(segD, SEGMENT_ON); 682 digitalWrite(segE, SEGMENT_OFF); 683 digitalWrite(segF, SEGMENT_ON); 684 digitalWrite(segG, SEGMENT_ON); 685 break; 686 case 10: //... FOR ALL DISP OFF 687 digitalWrite(segA, SEGMENT_OFF); 688 digitalWrite(segB, SEGMENT_OFF); 689 digitalWrite(segC, SEGMENT_OFF); 690 digitalWrite(segD, SEGMENT_OFF); 691 digitalWrite(segE, SEGMENT_OFF); 692 digitalWrite(segF, SEGMENT_OFF); 693 digitalWrite(segG, SEGMENT_OFF); 694 break; 695 696 697 case 11: //------FOR SHOWING A 698 digitalWrite(segA, SEGMENT_ON); 699 digitalWrite(segB, SEGMENT_ON); 700 digitalWrite(segC, SEGMENT_ON); 701 digitalWrite(segD, SEGMENT_OFF); 702 digitalWrite(segE, SEGMENT_ON); 703 digitalWrite(segF, SEGMENT_ON); 704 digitalWrite(segG, SEGMENT_ON); 705 break; 706 707 case 12: // ------FOR SHOWING L 708 digitalWrite(segA, SEGMENT_OFF); 709 digitalWrite(segB, SEGMENT_OFF); 710 digitalWrite(segC, SEGMENT_OFF); 711 digitalWrite(segD, SEGMENT_ON); 712 digitalWrite(segE, SEGMENT_ON); 713 digitalWrite(segF, SEGMENT_ON); 714 digitalWrite(segG, SEGMENT_OFF); 715 break; 716 717 case 13: //--- FOR SHOWING t 718 digitalWrite(segA, SEGMENT_OFF); 719 digitalWrite(segB, SEGMENT_OFF); 720 digitalWrite(segC, SEGMENT_OFF); 721 digitalWrite(segD, SEGMENT_ON); 722 digitalWrite(segE, SEGMENT_ON); 723 digitalWrite(segF, SEGMENT_ON); 724 digitalWrite(segG, SEGMENT_ON); 725 break; 726 727 case 14: //------FOR SHOWING S 728 digitalWrite(segA, SEGMENT_ON); 729 digitalWrite(segB, SEGMENT_OFF); 730 digitalWrite(segC, SEGMENT_ON); 731 digitalWrite(segD, SEGMENT_ON); 732 digitalWrite(segE, SEGMENT_OFF); 733 digitalWrite(segF, SEGMENT_ON); 734 digitalWrite(segG, SEGMENT_ON); 735 736 break; 737 738case 15: //------FOR SHOWING DEGREE SYMBOL 739 digitalWrite(segA, SEGMENT_ON); 740 digitalWrite(segB, SEGMENT_ON); 741 digitalWrite(segC, SEGMENT_OFF); 742 digitalWrite(segD, SEGMENT_OFF); 743 digitalWrite(segE, SEGMENT_OFF); 744 digitalWrite(segF, SEGMENT_ON); 745 digitalWrite(segG, SEGMENT_ON); 746 break; 747case 16: //------FOR SHOWING C 748 digitalWrite(segA, SEGMENT_ON); 749 digitalWrite(segB, SEGMENT_OFF); 750 digitalWrite(segC, SEGMENT_OFF); 751 digitalWrite(segD, SEGMENT_ON); 752 digitalWrite(segE, SEGMENT_ON); 753 digitalWrite(segF, SEGMENT_ON); 754 digitalWrite(segG, SEGMENT_OFF); 755 756 break; 757 758 759 } 760 } 761 762 //===============================================================- 763 void displaysecond(int sec) { 764#define BRIGHTNESS 1000 765#define BRIGHTNESS1 400 766 767#define DIGIT_ON HIGH 768#define DIGIT_OFF LOW 769 770 digitalWrite(digit1, DIGIT_OFF); 771 digitalWrite(digit2, DIGIT_OFF); 772 digitalWrite(digit3, DIGIT_OFF); 773 digitalWrite(digit4, DIGIT_OFF); 774 digitalWrite(digit6, DIGIT_OFF); 775 digitalWrite(digit5, DIGIT_OFF); 776 777 int yy = sec / 10; 778 int aa = sec % 10; 779 780 if (sec % 2 == 0 ) { 781 digitalWrite(Dot, LOW); 782 delayMicroseconds(BRIGHTNESS1); 783 } 784 else; 785 { digitalWrite(Dot, HIGH); 786 delayMicroseconds(BRIGHTNESS1); 787 } 788 789 digitalWrite(digit5, DIGIT_OFF); 790 digitalWrite(digit6, DIGIT_ON); 791 ShowNumber(aa ); 792 delayMicroseconds(BRIGHTNESS); 793 ShowNumber(10); 794 795 digitalWrite(digit6, DIGIT_OFF); 796 digitalWrite(digit5, DIGIT_ON); 797 ShowNumber(yy); 798 delayMicroseconds(BRIGHTNESS); 799 ShowNumber(10); 800 digitalWrite(digit6, DIGIT_OFF); 801 digitalWrite(digit5, DIGIT_OFF); 802 } 803 804 //=================================================================== 805 806 void displaychar(int charshow1 , int charshow2) { 807#define BRIGHTNESS 2000 808#define BRIGHTNESS1 400 809 810#define DIGIT_ON HIGH 811#define DIGIT_OFF LOW 812 813 digitalWrite(digit1, DIGIT_OFF); 814 digitalWrite(digit2, DIGIT_OFF); 815 digitalWrite(digit3, DIGIT_OFF); 816 digitalWrite(digit4, DIGIT_OFF); 817 818 digitalWrite(digit6, DIGIT_OFF); 819 digitalWrite(digit5, DIGIT_ON); 820 ShowNumber(charshow2); 821 delayMicroseconds(BRIGHTNESS); 822 ShowNumber(10); 823 824 digitalWrite(digit5, DIGIT_OFF); 825 digitalWrite(digit6, DIGIT_ON); 826 ShowNumber(charshow1 ); 827 delayMicroseconds(BRIGHTNESS); 828 829 digitalWrite(digit6, DIGIT_OFF); 830 digitalWrite(digit5, DIGIT_OFF); 831 ShowNumber(10); 832 } 833 834 //====================For storing alarnm data in flash memory=========== 835 836 void ALARMSTORE(int alm_set1 , int rw ) { 837 838 static unsigned int altim; 839 static unsigned int altim1; 840 int EEAddr = EEADDR; 841 int EEAddr1 = EEADDR1; 842 altim = alm_set1 % 100; 843 altim1 = alm_set1 / 100; 844 845 // Serial.print("EEPROM Written"); 846 847 848 if (rw == 1) { 849 850 EEPROM.update(EEAddr , altim); EEAddr += sizeof(altim); 851 EEPROM.update(EEAddr1 , altim1); EEAddr1 += sizeof(altim1); 852 853 alm_set = altim1 * 100 + altim; 854 alm_set1 = alm_set; 855 856 } 857 858 else {} 859 if (rw == 0) { 860 // EEPROM.get(EEAddr , altim); EEAddr += sizeof(altim); 861 862 } 863 else {} 864 865 } //-------------------- end of ALRMSTORE 866
Code For Digital Clock with IR remote
arduino
1//COMPLETE DIGITAL CLOCK WITH INFRARED REMOTE CONTROL BY AJITH KUMAR 2int 3 digit1 = A3; 4int digit2 = 9; 5int digit3 = 10; 6int digit4 = 12; 7int digit6 8 = 13; 9int digit5 = A2; 10int segA = 4; 11int segB = 5; 12int segC = 8; 13int 14 segD = 7; 15int segE = 6; 16int segF = 3; 17int segG = 2; 18int Dot = 1; 19int 20 Hrchime = A1; 21int Almout = A0; 22int Disp_mode = 0; 23int aset; 24int aset1 25 = 3; // set value as 3 for first time retrival of alarm set 26int HCperiod 27 = 12; // required time for hour chime in seconds 28int snoozperiod = 5; // required 29 time to repeat alarm snooz in minutes 30int almperiod = 20; // maximum time of 31 alarm ringing before auto off 32int dtt2; 33int snoozflag = 0; 34int snoozset 35 = 0; 36int setmode = 0; 37int dispoff_flag = 1; 38int keyx; 39int count = 0; 40int 41 keysum; 42int keysum1; 43int keyvalid; 44int set_mode = 0; 45int time_set = 46 0 ; 47int alm_set; 48int alm_set1; 49int charshow1; 50int charshow2; 51int 52 timp2; 53int typeset = 0; 54int beep_onoff = 0; 55 56static unsigned int altim; 57static 58 unsigned int altim1; 59unsigned long key_value = 0; 60 61 62//#include <Wire.h> 63#include 64 "RTClib.h" 65#include <EEPROM.h> 66#include <IRremote.h> 67 68 69#define 70 RECEIVER_PIN 11 71#define EEADDR 174 // Start location to write EEPROM data. 72#define 73 EEADDR1 188 74RTC_DS3231 RTC; 75IRrecv receiver(RECEIVER_PIN); 76decode_results 77 results; 78 79void ShowNumber(int ); 80void displaychar(int , int); 81void Light_HR_MIN(int); 82void 83 displaysecond(int ); 84void IRR(int , int); 85void ALARMSTORE(int , int); 86 87//========================================================================================================== 88void 89 setup() { 90 //Serial.begin(9600); 91 92 RTC.begin(); 93 DateTime now = RTC.now(); 94 95 //RTC.adjust(DateTime(__DATE__, __TIME__));// for setting clock remove // from 96 this line and upload sketch 97 //after setting clock again put // on the line 98 and upload once more 99 100 pinMode(segA, OUTPUT); 101 pinMode(segB, OUTPUT); 102 103 pinMode(segC, OUTPUT); 104 pinMode(segD, OUTPUT); 105 pinMode(segE, OUTPUT); 106 107 pinMode(segF, OUTPUT); 108 pinMode(segG, OUTPUT); 109 pinMode(Dot, OUTPUT); 110 111 pinMode(Hrchime, OUTPUT); 112 pinMode(digit1, OUTPUT); 113 pinMode(digit2, OUTPUT); 114 115 pinMode(digit3, OUTPUT); 116 pinMode(digit4, OUTPUT); 117 pinMode(digit5, OUTPUT); 118 119 pinMode(digit6, OUTPUT); 120 pinMode(Almout, OUTPUT); 121 digitalWrite(Almout, 122 LOW); 123 digitalWrite(Hrchime, LOW); 124 digitalWrite(Almout, LOW); 125 126 127 128 // ------------------------------retrieving alarm set time from flash on power_on 129 130 131 int EEAddr = EEADDR; 132 int EEAddr1 = EEADDR1; 133 if (aset1 == 3 ) { 134 135 136 EEPROM.get(EEAddr , altim); EEAddr += sizeof(altim); 137 EEPROM.get(EEAddr1 138 , altim1); EEAddr1 += sizeof(altim1); 139 alm_set = altim1 * 100 + altim; 140 141 aset1 = 6; 142 aset = 7; 143 alm_set1 = alm_set; 144 } 145 else {} 146 147 148 //-------end of alrm set time reading from flash 149 150 receiver.enableIRIn(); 151 // enable the receiver 152 int IRR(int); 153} 154 155//========================================END 156 OF SETUP=================================== 157 158void loop() { // ==========================VOID 159 LOOP===================================== 160 161 162 163 //====================================DISPLAY 164 OFF FUNCTION.============================== 165 if ( dispoff_flag == 0) { 166 digitalWrite(digit1, 167 LOW); 168 digitalWrite(digit2, LOW); 169 digitalWrite(digit3, LOW); 170 digitalWrite(digit4, 171 LOW); 172 digitalWrite(digit5, LOW); 173 digitalWrite(digit6, LOW); 174 } 175 176 else { 177 178 //=================================TEMPERATURE DISPLAY ==================================== 179 180 181 if (Disp_mode == 4) { 182 float tempC = RTC.getTemperature(); 183 tempC 184 = tempC * 100; 185 186 for (int i = 8 ; i > 0 ; i--) { 187 Light_HR_MIN(tempC); 188 189 displaychar(16 , 15) ; 190 } 191 192 } 193 else{} 194 195 //=================================REAL 196 TIME DISPLAY======================================== 197 198 if (Disp_mode == 199 0) { 200 201 DateTime now = RTC.now(); 202 int tim = (now.hour()); 203 204 205 if (tim > 12) { 206 tim = tim - 12; 207 } 208 else; 209 210 if (tim == 0) { 211 tim = 12; 212 } 213 else; 214 int 215 timp = (tim * 100 + now.minute()); 216 int timp1 = now.second(); 217 timp2 218 = (now.hour() + now.minute()); 219 220 221 // For Digits display 222 for 223 (int i = 10 224 ; i > 0 ; i--) { 225 Light_HR_MIN(timp); 226 227 displaysecond(timp1); 228 } 229 } 230 231 else {} 232 233 } 234 235 //------------------------------------------------------------------------------------------- 236 237 //===============================CHECKING REMOTE PESSING===================================== 238 239 240 if (receiver.decode(&results)) { 241 242 //Serial.println("KEY RESULT"); 243 // remove // of this line and next line to find the ir code of an unknown IR 244 receiver 245 // Serial.println(results.value, HEX); 246 247 248 249 if (results.value 250 == 0x1FE7887) { //=======TEMPERATURE DIDPLAY KEY PRESSED============== 251 Disp_mode 252 = 4; 253 } 254 else 255 { receiver.resume(); 256 } 257 258//=============================================RETURN 259 KEY PRESSED============================= 260 if (results.value == 0x1FE58A7) { 261 262 263 typeset = 0; 264 Disp_mode = 0; 265 } 266 //=========================================================================================== 267 268 269 if (results.value == 0x1FE40BF) { //=========== ALARM SET KEY PRESSED================== 270 271 typeset = 1; 272 setmode = 0; 273 //almblow=0; 274 Disp_mode 275 = 1; 276 keysum1 = alm_set; 277 278 IRR( keysum1 , 1); 279 receiver.resume(); 280 281 alm_set = keysum1; 282 283 ALARMSTORE(alm_set , 1 ); 284 aset 285 = 6; 286 287 } 288 else { 289 290 typeset = 0; 291 Disp_mode 292 == 0; 293 } 294 295 //========================================================================================== 296 297 298 if (results.value == 0x1FEC03F) { // ============== TIME SET KEY PRESSED==================== 299 300 typeset = 2; 301 setmode = 1; 302 303 Disp_mode = 1; 304 DateTime 305 now = RTC.now(); 306 dtt2 = now.hour() * 100 + now.minute(); 307 308 IRR( 309 dtt2 , 2); 310 receiver.resume(); 311 312 //Serial.println(" "); 313 314 315 //Serial.print("TIME SET= "); 316 317 //Serial.println(keysum1); 318 319 int newtime = keysum1; 320 int h1 = newtime / 100; 321 int 322 m1 = newtime % 100; 323 324 RTC.adjust(DateTime(2021, 1, 1, h1, m1, 0)); 325 326 327 } 328 else { 329 receiver.resume(); 330 } 331 //================================================================================================= 332 333 334 if (results.value == 0x1FEA05F) { //===============ALARM OFF KEY PRESSED========================== 335 336 337 Serial.print("ALM OFF "); 338 beep_onoff = 0; 339 snoozflag 340 = 0; 341 //Serial.print(almblow); 342 } 343 else { 344 receiver.resume(); 345 346 } 347 348 //================================================================================================ 349 350 351 if (results.value == 0x1FE609F) { //============ SNOOZ ON KEY PRESSED============================= 352 353 delay(100); 354 // Serial.print("SNOOZ ON "); 355 356 snoozset 357 = snoozset + snoozperiod; 358 snoozflag = 1; 359 Serial.print("snooz 360 on "); 361 Serial.print(snoozset); 362 //digitalWrite(Almout, LOW); 363 364 beep_onoff = 0; 365 } 366 else { 367 receiver.resume(); 368 369 } 370 //=================================================================================================== 371 372 373 374 if (results.value == 0x1FE48B7) { //============OFF/ ON KEY (DISPLAY OFF) 375 KEY PRESSED=============== 376 377 //Serial.print("display off OFF "); 378 379 //digitalWrite(Almout, LOW); 380 dispoff_flag = abs(dispoff_flag 381 - 1); 382 383 delay(500); 384 } 385 386 else { 387 receiver.resume(); 388 389 } 390 } 391 392 //================================END OD REMOTE KEY 393 PRESS CHECK======================================= 394 // ==================================ALARM 395 CHECKING==================================================== 396 DateTime now 397 = RTC.now(); 398 int xc = now.hour() * 100 + now.minute(); 399 int yc = now.second(); 400 401 402 if (xc == alm_set && yc == 1 ) { 403 //digitalWrite(Almout, HIGH); 404 405 snoozset = alm_set; 406 beep_onoff = 1; 407 408 } 409 else {} 410 411 412 if (snoozflag == 1) { 413 414 if (xc == snoozset && yc <= 1 ) { 415 416 417 beep_onoff = 1; 418 //digitalWrite(Almout, HIGH); 419 } 420 421 else {} 422 } 423 424 else {} 425 426 if ( xc == alm_set + almperiod 427 ) { 428 //digitalWrite(Almout, LOW); 429 430 beep_onoff = 0; 431 snoozflag 432 = 0; 433 } 434 else {} 435 436 //===============================Alarm Beeping 437 =========================================================== 438 439 if (beep_onoff 440 == 1 ) { 441 442 443 if (yc % 2 == 0) 444 digitalWrite(Almout, HIGH); 445 446 else 447 digitalWrite(Almout, LOW); 448 } 449 450 else 451 452 453 digitalWrite(Almout, LOW); 454 455 //========================================== 456 hour chime=============================================== 457 458 459 int w1 460 = now.minute(); 461 int w2 = now.second(); 462 463 if (w1 == 0 && w2 <= 464 HCperiod ) { 465 digitalWrite(Hrchime, HIGH); 466 } 467 else { 468 digitalWrite(Hrchime 469 , LOW); 470 } 471 472 473 474 } //=================================END OF MAIN 475 LOOP VOID()========================================== 476 477 //=============================SUB 478 PROGRAMMES========================================================== 479 480 481 482 void IRR( int keysum , int typeset ) { 483 484 485 while (typeset != 0) { 486 487 488 if (typeset == 1) { 489 for (int i = 8 ; i > 0 ; i--) { 490 491 Light_HR_MIN(keysum); 492 493 displaychar(12 , 11) ; 494 Light_HR_MIN(keysum); 495 } 496 497 } 498 else {} 499 500 if (typeset == 2) { 501 for (int i 502 = 8 ; i > 0 ; i--) { 503 Light_HR_MIN(keysum); 504 displaychar(13 505 , 14) ; 506 Light_HR_MIN(keysum); 507 } 508 } 509 else 510 {} 511 512 if (receiver.decode(&results)) { 513 514 515 switch (results.value) 516 { 517 518 case 0x1FE58A7://------------------------------RETURN KEY PRESSED-------------------------- 519 520 typeset = 0; 521 Disp_mode = 0; 522 break; 523 524 525 //----------------------------------------------------------------------------------------- 526 527 528 529 530 case 0x1FE20DF: // -----------------------PRESSING ENTER KEY---------------------------- 531 532 533 534 if ( keysum / 10 == 0 && keysum >= 60 ) { 535 count = 536 0; 537 keysum = 0; 538 keyvalid = 0; 539 } 540 541 else {} 542 543 if ( keysum / 100 == 0 && keysum >= 60) { 544 545 count = 0; 546 keysum = 0; 547 keyvalid 548 = 0; 549 } 550 else {} 551 552 553 if ( keysum 554 / 100 == 0 && keysum / 1000 == 0 && keysum % 100 >= 60 ) { 555 count 556 = 0; 557 keysum = 0; 558 keyvalid = 0; 559 } 560 561 else {} 562 563 if ( keysum / 10000 == 0 && keysum % 564 100 >= 60 ) { 565 count = 0; 566 keysum = 0; 567 keyvalid 568 = 0; 569 } 570 else { 571 } 572 if (keyvalid 573 == 1) { 574 typeset = 0; 575 Disp_mode = 0; 576 } 577 578 else {} 579 580 break ; 581 582 case 0x1FE50AF: 583 //..........KEY 1.... 584 keysum = keysum * 10 + keyx; 585 count 586 = count + 1; 587 break; 588 case 0x1FED827: //........KEY 589 2..... 590 keyx = 2; 591 count = count + 1; 592 keysum 593 = keysum * 10 + keyx; 594 break; 595 case 0x1FEF807: //........KEY 596 3 .... 597 keyx = 3; 598 count = count + 1; 599 keysum 600 = keysum * 10 + keyx; 601 break; 602 case 0x1FE30CF: //........KEY 603 4..... 604 keyx = 4; 605 count = count + 1; 606 keysum 607 = keysum * 10 + keyx; 608 break ; 609 case 0x1FEB04F: //........KEY 610 5..... 611 keyx = 5; 612 count = count + 1; 613 keysum 614 = keysum * 10 + keyx; 615 break ; 616 case 0x1FE708F: //........KEY 617 6..... 618 keyx = 6; 619 count = count + 1; 620 keysum 621 = keysum * 10 + keyx; 622 break ; 623 case 0x1FE00FF: //........KEY 624 7..... 625 keyx = 7; 626 count = count + 1; 627 keysum 628 = keysum * 10 + keyx; 629 break ; 630 case 0x1FEF00F: //........KEY 631 8..... 632 keyx = 8; 633 count = count + 1; 634 keysum 635 = keysum * 10 + keyx; 636 break ; 637 case 0x1FE9867: //........KEY 638 9..... 639 keyx = 9; 640 count = count + 1; 641 keysum 642 = keysum * 10 + keyx; 643 break ; 644 case 0x1FEE01F: //........KEY 645 0..... 646 keyx = 0; 647 count = count + 1; 648 keysum 649 = keysum * 10 + keyx; 650 break ; 651 652 } // 653 //-------------------------------------------------------------------------- 654 655 if (count >= 5) { 656 count = 0; 657 keysum = 0; 658 } 659 660 else {} 661 662 if (keysum >= 2400) { 663 keysum = 0; 664 665 count = 0; 666 } 667 else {} 668 669 if (keysum <= 670 0) { 671 keysum = 0; 672 count = 0; 673 } 674 else 675 {} 676 677 key_value = results.value; 678 keyvalid = 1; 679 keysum1 680 = keysum; 681 682 if (typeset == 1) { 683 alm_set = keysum; 684 685 686 } 687 else {} 688 689 if (typeset == 2) { 690 time_set 691 = keysum; 692 } 693 else {} 694 695 delay(50); 696 receiver.resume(); 697 698 } 699 } 700 } 701 //============================================================================================ 702 703 void Light_HR_MIN(int toDisplay) { 704#define BRIGHTNESS 1000 705#define DIGIT_ON 706 HIGH 707#define DIGIT_OFF LOW 708 int hrr = toDisplay / 100; 709 710 if 711 (Disp_mode == 1) 712 { digitalWrite(digit5, LOW); 713 digitalWrite(digit6, 714 LOW); 715 } 716 else {} 717 718 for (int digit = 4 ; digit > 0 ; digit--) 719 { 720 switch (digit) { 721 722 case 1: 723 if (hrr < 10 && 724 hrr != 0 ) 725 { 726 digitalWrite(digit1, DIGIT_OFF); 727 } 728 729 else { 730 digitalWrite(digit1, DIGIT_ON); 731 } 732 733 break; 734 case 2: 735 digitalWrite(digit2, DIGIT_ON); 736 737 break; 738 case 3: 739 digitalWrite(digit3, DIGIT_ON); 740 741 break; 742 case 4: 743 digitalWrite(digit4, DIGIT_ON); 744 745 break; 746 } 747 748 ShowNumber(toDisplay % 10); 749 toDisplay 750 /= 10; 751 delayMicroseconds(BRIGHTNESS); 752 ShowNumber(10); 753 //Turn 754 off all digits 755 digitalWrite(digit1, DIGIT_OFF); 756 digitalWrite(digit2, 757 DIGIT_OFF); 758 digitalWrite(digit3, DIGIT_OFF); 759 digitalWrite(digit4, 760 DIGIT_OFF); 761 } 762 } 763 764 //======================================================================= 765 766 void ShowNumber(int numberToDisplay) { 767 768#define SEGMENT_ON LOW 769#define 770 SEGMENT_OFF HIGH 771 772 switch (numberToDisplay) { 773 case 0: 774 775 776 digitalWrite(segA, SEGMENT_ON); 777 digitalWrite(segB, SEGMENT_ON); 778 779 digitalWrite(segC, SEGMENT_ON); 780 digitalWrite(segD, SEGMENT_ON); 781 782 digitalWrite(segE, SEGMENT_ON); 783 digitalWrite(segF, SEGMENT_ON); 784 785 digitalWrite(segG, SEGMENT_OFF); 786 787 break; 788 case 1: 789 790 digitalWrite(segA, SEGMENT_OFF); 791 digitalWrite(segB, SEGMENT_ON); 792 793 digitalWrite(segC, SEGMENT_ON); 794 digitalWrite(segD, SEGMENT_OFF); 795 796 digitalWrite(segE, SEGMENT_OFF); 797 digitalWrite(segF, SEGMENT_OFF); 798 799 digitalWrite(segG, SEGMENT_OFF); 800 break; 801 case 2: 802 803 digitalWrite(segA, SEGMENT_ON); 804 digitalWrite(segB, SEGMENT_ON); 805 806 digitalWrite(segC, SEGMENT_OFF); 807 digitalWrite(segD, SEGMENT_ON); 808 809 digitalWrite(segE, SEGMENT_ON); 810 digitalWrite(segF, SEGMENT_OFF); 811 812 digitalWrite(segG, SEGMENT_ON); 813 break; 814 case 3: 815 digitalWrite(segA, 816 SEGMENT_ON); 817 digitalWrite(segB, SEGMENT_ON); 818 digitalWrite(segC, 819 SEGMENT_ON); 820 digitalWrite(segD, SEGMENT_ON); 821 digitalWrite(segE, 822 SEGMENT_OFF); 823 digitalWrite(segF, SEGMENT_OFF); 824 digitalWrite(segG, 825 SEGMENT_ON); 826 break; 827 case 4: 828 digitalWrite(segA, SEGMENT_OFF); 829 830 digitalWrite(segB, SEGMENT_ON); 831 digitalWrite(segC, SEGMENT_ON); 832 833 digitalWrite(segD, SEGMENT_OFF); 834 digitalWrite(segE, SEGMENT_OFF); 835 836 digitalWrite(segF, SEGMENT_ON); 837 digitalWrite(segG, SEGMENT_ON); 838 839 break; 840 case 5: 841 digitalWrite(segA, SEGMENT_ON); 842 digitalWrite(segB, 843 SEGMENT_OFF); 844 digitalWrite(segC, SEGMENT_ON); 845 digitalWrite(segD, 846 SEGMENT_ON); 847 digitalWrite(segE, SEGMENT_OFF); 848 digitalWrite(segF, 849 SEGMENT_ON); 850 digitalWrite(segG, SEGMENT_ON); 851 break; 852 case 853 6: 854 digitalWrite(segA, SEGMENT_ON); 855 digitalWrite(segB, SEGMENT_OFF); 856 857 digitalWrite(segC, SEGMENT_ON); 858 digitalWrite(segD, SEGMENT_ON); 859 860 digitalWrite(segE, SEGMENT_ON); 861 digitalWrite(segF, SEGMENT_ON); 862 863 digitalWrite(segG, SEGMENT_ON); 864 break; 865 case 7: 866 digitalWrite(segA, 867 SEGMENT_ON); 868 digitalWrite(segB, SEGMENT_ON); 869 digitalWrite(segC, 870 SEGMENT_ON); 871 digitalWrite(segD, SEGMENT_OFF); 872 digitalWrite(segE, 873 SEGMENT_OFF); 874 digitalWrite(segF, SEGMENT_OFF); 875 digitalWrite(segG, 876 SEGMENT_OFF); 877 break; 878 case 8: 879 digitalWrite(segA, SEGMENT_ON); 880 881 digitalWrite(segB, SEGMENT_ON); 882 digitalWrite(segC, SEGMENT_ON); 883 884 digitalWrite(segD, SEGMENT_ON); 885 digitalWrite(segE, SEGMENT_ON); 886 887 digitalWrite(segF, SEGMENT_ON); 888 digitalWrite(segG, SEGMENT_ON); 889 890 break; 891 case 9: 892 digitalWrite(segA, SEGMENT_ON); 893 digitalWrite(segB, 894 SEGMENT_ON); 895 digitalWrite(segC, SEGMENT_ON); 896 digitalWrite(segD, 897 SEGMENT_ON); 898 digitalWrite(segE, SEGMENT_OFF); 899 digitalWrite(segF, 900 SEGMENT_ON); 901 digitalWrite(segG, SEGMENT_ON); 902 break; 903 case 904 10: //... FOR ALL DISP OFF 905 digitalWrite(segA, SEGMENT_OFF); 906 digitalWrite(segB, 907 SEGMENT_OFF); 908 digitalWrite(segC, SEGMENT_OFF); 909 digitalWrite(segD, 910 SEGMENT_OFF); 911 digitalWrite(segE, SEGMENT_OFF); 912 digitalWrite(segF, 913 SEGMENT_OFF); 914 digitalWrite(segG, SEGMENT_OFF); 915 break; 916 917 918 919 case 11: //------FOR SHOWING A 920 digitalWrite(segA, SEGMENT_ON); 921 922 digitalWrite(segB, SEGMENT_ON); 923 digitalWrite(segC, SEGMENT_ON); 924 925 digitalWrite(segD, SEGMENT_OFF); 926 digitalWrite(segE, SEGMENT_ON); 927 928 digitalWrite(segF, SEGMENT_ON); 929 digitalWrite(segG, SEGMENT_ON); 930 931 break; 932 933 case 12: // ------FOR SHOWING L 934 digitalWrite(segA, 935 SEGMENT_OFF); 936 digitalWrite(segB, SEGMENT_OFF); 937 digitalWrite(segC, 938 SEGMENT_OFF); 939 digitalWrite(segD, SEGMENT_ON); 940 digitalWrite(segE, 941 SEGMENT_ON); 942 digitalWrite(segF, SEGMENT_ON); 943 digitalWrite(segG, 944 SEGMENT_OFF); 945 break; 946 947 case 13: //--- FOR SHOWING t 948 digitalWrite(segA, 949 SEGMENT_OFF); 950 digitalWrite(segB, SEGMENT_OFF); 951 digitalWrite(segC, 952 SEGMENT_OFF); 953 digitalWrite(segD, SEGMENT_ON); 954 digitalWrite(segE, 955 SEGMENT_ON); 956 digitalWrite(segF, SEGMENT_ON); 957 digitalWrite(segG, 958 SEGMENT_ON); 959 break; 960 961 case 14: //------FOR SHOWING S 962 digitalWrite(segA, 963 SEGMENT_ON); 964 digitalWrite(segB, SEGMENT_OFF); 965 digitalWrite(segC, 966 SEGMENT_ON); 967 digitalWrite(segD, SEGMENT_ON); 968 digitalWrite(segE, 969 SEGMENT_OFF); 970 digitalWrite(segF, SEGMENT_ON); 971 digitalWrite(segG, 972 SEGMENT_ON); 973 974 break; 975 976case 15: //------FOR SHOWING DEGREE SYMBOL 977 978 digitalWrite(segA, SEGMENT_ON); 979 digitalWrite(segB, SEGMENT_ON); 980 981 digitalWrite(segC, SEGMENT_OFF); 982 digitalWrite(segD, SEGMENT_OFF); 983 984 digitalWrite(segE, SEGMENT_OFF); 985 digitalWrite(segF, SEGMENT_ON); 986 987 digitalWrite(segG, SEGMENT_ON); 988 break; 989case 16: //------FOR 990 SHOWING C 991 digitalWrite(segA, SEGMENT_ON); 992 digitalWrite(segB, 993 SEGMENT_OFF); 994 digitalWrite(segC, SEGMENT_OFF); 995 digitalWrite(segD, 996 SEGMENT_ON); 997 digitalWrite(segE, SEGMENT_ON); 998 digitalWrite(segF, 999 SEGMENT_ON); 1000 digitalWrite(segG, SEGMENT_OFF); 1001 1002 break; 1003 1004 1005 1006 } 1007 } 1008 1009 //===============================================================- 1010 1011 void displaysecond(int sec) { 1012#define BRIGHTNESS 1000 1013#define BRIGHTNESS1 1014 400 1015 1016#define DIGIT_ON HIGH 1017#define DIGIT_OFF LOW 1018 1019 digitalWrite(digit1, 1020 DIGIT_OFF); 1021 digitalWrite(digit2, DIGIT_OFF); 1022 digitalWrite(digit3, 1023 DIGIT_OFF); 1024 digitalWrite(digit4, DIGIT_OFF); 1025 digitalWrite(digit6, 1026 DIGIT_OFF); 1027 digitalWrite(digit5, DIGIT_OFF); 1028 1029 int yy = sec / 10; 1030 1031 int aa = sec % 10; 1032 1033 if (sec % 2 == 0 ) { 1034 digitalWrite(Dot, 1035 LOW); 1036 delayMicroseconds(BRIGHTNESS1); 1037 } 1038 else; 1039 { digitalWrite(Dot, 1040 HIGH); 1041 delayMicroseconds(BRIGHTNESS1); 1042 } 1043 1044 digitalWrite(digit5, 1045 DIGIT_OFF); 1046 digitalWrite(digit6, DIGIT_ON); 1047 ShowNumber(aa ); 1048 delayMicroseconds(BRIGHTNESS); 1049 1050 ShowNumber(10); 1051 1052 digitalWrite(digit6, DIGIT_OFF); 1053 digitalWrite(digit5, 1054 DIGIT_ON); 1055 ShowNumber(yy); 1056 delayMicroseconds(BRIGHTNESS); 1057 ShowNumber(10); 1058 1059 digitalWrite(digit6, DIGIT_OFF); 1060 digitalWrite(digit5, DIGIT_OFF); 1061 1062 } 1063 1064 //=================================================================== 1065 1066 1067 void displaychar(int charshow1 , int charshow2) { 1068#define BRIGHTNESS 2000 1069#define 1070 BRIGHTNESS1 400 1071 1072#define DIGIT_ON HIGH 1073#define DIGIT_OFF LOW 1074 1075 1076 digitalWrite(digit1, DIGIT_OFF); 1077 digitalWrite(digit2, DIGIT_OFF); 1078 1079 digitalWrite(digit3, DIGIT_OFF); 1080 digitalWrite(digit4, DIGIT_OFF); 1081 1082 1083 digitalWrite(digit6, DIGIT_OFF); 1084 digitalWrite(digit5, DIGIT_ON); 1085 1086 ShowNumber(charshow2); 1087 delayMicroseconds(BRIGHTNESS); 1088 ShowNumber(10); 1089 1090 1091 digitalWrite(digit5, DIGIT_OFF); 1092 digitalWrite(digit6, DIGIT_ON); 1093 1094 ShowNumber(charshow1 ); 1095 delayMicroseconds(BRIGHTNESS); 1096 1097 digitalWrite(digit6, 1098 DIGIT_OFF); 1099 digitalWrite(digit5, DIGIT_OFF); 1100 ShowNumber(10); 1101 } 1102 1103 1104 //====================For storing alarnm data in flash memory=========== 1105 1106 1107 void ALARMSTORE(int alm_set1 , int rw ) { 1108 1109 static unsigned int altim; 1110 1111 static unsigned int altim1; 1112 int EEAddr = EEADDR; 1113 int EEAddr1 = 1114 EEADDR1; 1115 altim = alm_set1 % 100; 1116 altim1 = alm_set1 / 100; 1117 1118 1119 // Serial.print("EEPROM Written"); 1120 1121 1122 if (rw == 1) { 1123 1124 EEPROM.update(EEAddr 1125 , altim); EEAddr += sizeof(altim); 1126 EEPROM.update(EEAddr1 , altim1); EEAddr1 1127 += sizeof(altim1); 1128 1129 alm_set = altim1 * 100 + altim; 1130 alm_set1 1131 = alm_set; 1132 1133 } 1134 1135 else {} 1136 if (rw == 0) { 1137 // EEPROM.get(EEAddr 1138 , altim); EEAddr += sizeof(altim); 1139 1140 } 1141 else {} 1142 1143 } //-------------------- 1144 end of ALRMSTORE 1145
Downloadable files
DETAILS OF CONSTRUCTION
DETAILS OF CONSTRUCTION
LayOut and pin ConFiguration
LayOut and pin ConFiguration
CIRCUIT DIAGRAM
CIRCUIT DIAGRAM
DETAILS OF CONSTRUCTION
DETAILS OF CONSTRUCTION
LayOut and pin ConFiguration
LayOut and pin ConFiguration
Comments
Only logged in users can leave comments