Components and supplies
MM5451
High Accuracy Pi RTC (DS3231)
5 mm LED: Green
Toggle Switch, (On)-Off-(On)
Rotary Encoder with Push-Button
Arduino UNO
Resistor 330 ohm
7 Segment LED Display, InfoVue
5 mm LED: Red
Shift Register- Serial to Parallel
Apps and platforms
Arduino IDE
Project description
Code
60 led clock analog style
arduino
Analog style clock
1#define PI 3.141592653589793 2#define DEG_TO_RAD 0.0174532925 3#define 4 RAD_TO_DEG 57.2957795130 5#include <Wire.h> 6#define CLK 5 7#define Latch 8 6 9#define dataBit 7// serial data 10#define CLKMM 4 // to MM5451 pin 21 11#define 12 dataBitMM 3 // to MM5451 pin 22 13#define DecPunt 8 // dot display 14#define 15 SW1 12 16#define SW2 11 17#define SW3 10 18#define SW4 9 19#include "Button2.h"; 20 // https://github.com/LennartHennigs/Button2 21#include "Rotary.h"; 22#define 23 ROTARY_PIN1 A0 24#define ROTARY_PIN2 A1 25#define BUTTON_PIN A2 26#define CLICKS_PER_STEP 27 4 // this number depends on your rotary encoder 28#define MIN_POS -100 29#define 30 MAX_POS 100 31#define START_POS 0 32#define INCREMENT 1 // 33 this number is the counter increment on each step 34Button2 bt; 35Rotary rt; 36 37//------------------------------------------------ 38// 39 7-segment display code array MM5451 40byte segCode[18] = {63, 6, 91, 79, 102, 109, 41 125, 7, 127, 111, 42 0b0001001, 0b1000000, 43 0b1011110, 44 0b0111001, 0b1011100, 45 0b1000000, 0b0000000, 0b0001000 46 47 }; 48//----------------------------------------------- 49byte 50 segCode2[12] = { 51 0b1000000, 0b0001001, 0b1011110, 52 0b1110111, 0b1101110, 53 0b0000000, 54 0b0100011, 0b0100111, 0b1001001, 55 0b0000000, 0b0111000, 0b1010100 56}; 57//------------------------------------------- 58byte 59 bindec[10] = { 60 16, 61 8, 62 4, 63 2, 64 1, 65 16, 66 8, 67 4, 68 69 2, 70 1, 71}; 72 73byte Maan[20] = { 2, 13, 24, 5, 16, 27, 8, 19, 30, 11, 74 22, 3, 14, 25, 6, 17, 29, 10, 21 }; 75// epacta getallen 76//eerste getal 2 is 77 het jaar 2017, maan is dan 2 dagen oud op 1 januari. 78// volgende getal is 2018, 79 maan is dan 13 dagen oud op 1 januari. 80//elk jaar verschuift 11, behalve eens 81 in de 19 jaar, dan 12. 82// laatste was in 2014 dan in 2033, en in 2052, en in 83 2071 enz. 84// 85//----------------------english------------------------------------------- 86//epacta 87 numbers 88// first number of array Maan[20] is 2. This number is the year 2017, 89 the moon age in days is 2 on januari first 90//The next number is 2018, the moon 91 age in days is 13 also on januari first, etc.. 92// every year ads 11, except once 93 in 19 years, then it wil be 12 94// latest was in 2014, then in 2033 etc... 95// 96 moonage = 0 >> new moon, moonage = 15 >> full moon 97// moonage = 7.5 >> first 98 quarter, moonage = 22.5 >> last quarter 99// from new moon to the next new moon 100 = 29.5 days 101byte Schrikkel = 0; 102int Dagtotaal[12] = { 0, 31, 59, 90, 120, 103 151, 181, 212, 243, 273, 304, 334 }; 104int DagtotaalS[12] = { 0, 31, 60, 91, 121, 105 152, 182, 213, 244, 274, 305, 335 }; 106byte AR; 107byte second; 108int minute; 109int 110 hour; 111byte weekday; 112byte monthDay; 113byte month; 114byte Test; 115byte test1; 116byte 117 test2; 118byte test3; 119byte test4; 120int year; 121byte Sjaar; 122byte a = 0; 123byte 124 b = 0; 125byte c = 0; 126byte d = 0; 127byte e = 0; 128byte f = 0; 129byte g = 0; 130byte 131 h = 0; 132byte i = 0; 133byte j = 0; 134byte k = 0; 135byte m = 0; 136byte CodeSec[15]; 137byte 138 CodeMin[15]; 139byte CodeLedMS[15]; 140byte Codemaan[15]; 141byte Lentepunt; 142int 143 Dagen; 144float ZonOp; 145float ZonOnder; 146float MoonAge; 147float DagLengte; 148byte 149 WT = 1; 150// The variables HDT,TDT,DT,HT,TT and EH are used in the subroutine Factor(); 151long 152 HDT;// hundred thousand ( when number is 123456, HDT = 1) 153long TDT;// ten thousand 154 ( when number is 123456, TDT = 2) 155long DT;//thousand ( when number is 123456, 156 DT = 3) 157long HT;// hundred ( when number is 123456, HT = 4) 158long TT;// tens 159 ( when the number is 123456, TT = 5) 160long EH;// unity (when the number is 123456, 161 EH = 6) 162byte cc; 163volatile int encoderPos = 0; 164boolean buttonPressed = 0; 165 // a flag variabl 166volatile byte secondsInterrupt = 0; 167const 168 byte interruptPin = 2; 169int counter = 0; 170//------------------------------------------------------- 171void 172 setup() { 173 pinMode(SW1, INPUT); 174 pinMode(SW2, INPUT); 175 pinMode(SW3, 176 INPUT); 177 pinMode(SW4, INPUT); 178 pinMode(DecPunt, OUTPUT); 179 pinMode(CLK, 180 OUTPUT); 181 pinMode(Latch, OUTPUT); 182 pinMode(dataBit, OUTPUT); 183 pinMode(CLKMM, 184 OUTPUT); 185 pinMode(dataBitMM, OUTPUT); 186 187 pinMode(interruptPin, INPUT_PULLUP); 188 189 Serial.begin(9600); 190 Wire.begin(); 191 attachInterrupt(digitalPinToInterrupt(interruptPin), 192 secondsRTC, FALLING); 193 bt.begin(BUTTON_PIN); 194 bt.setPressedHandler(pressed); 195 196 bt.setReleasedHandler(released); 197 198 rt.begin(ROTARY_PIN1, ROTARY_PIN2, CLICKS_PER_STEP, 199 MIN_POS, MAX_POS, START_POS, INCREMENT); 200 rt.setLeftRotationHandler(showDirection); 201 202 rt.setRightRotationHandler(showDirection); 203 zet_24uurmode(); 204 SQW1hzOn(); 205 206 digitalWrite(DecPunt, 1); 207 digitalWrite(dataBitMM, 1); 208 TijdUitlezen(); 209 210 pulseCLKMM(); 211 zeroWrite(35); 212 Reset60Led(); 213 Displaytest(); 214 Led60Test(); 215} 216//------------------------------------------------------------------------ 217byte 218 AgingRead() { 219 return leesroutine(16); 220} 221 222//------------------------------------------------------------------------ 223void 224 zet_24uurmode() {// set 24 hour mode 225 byte uurreg; 226 uurreg = leesroutine(2); 227 228 229 if (uurreg > 64) { // bit 6 = 64, set to zero 230 uurreg = uurreg - 64; 231 232 instelroutine(2, uurreg); 233 } 234} 235 236 237//------------------------------------------------------------------------ 238byte 239 lees_seconde() { // read seconds 240 return BcdToDec(leesroutine(0)); 241} 242//------------------------------------------------------------------------ 243byte 244 lees_minuut() { //read minute 245 return BcdToDec(leesroutine(1)); 246} 247//------------------------------------------------------------------------ 248byte 249 lees_uur() { // read hour 250 return BcdToDec(leesroutine(2)); 251} 252//------------------------------------------------------------------------ 253byte 254 lees_dagweek() { // read DOW 255 return BcdToDec(leesroutine(3)); 256} 257//------------------------------------------------------------------------ 258byte 259 lees_datum() { // read day of month 260 return BcdToDec(leesroutine(4)); 261} 262//------------------------------------------------------------------------ 263byte 264 lees_maand() { // read month 265 return BcdToDec(leesroutine(5)); 266} 267 268//------------------------------------------------------------------------ 269byte 270 lees_jaar() { // read year 271 return BcdToDec(leesroutine(6)); 272} 273//------------------------------------------------------------------------ 274byte 275 BcdToDec(byte val) { 276 return (val / 16 * 10) + (val % 16);// bcd to decimal 277} 278//------------------------------------------------------------------------ 279byte 280 leesroutine(byte adres) {// read register of RTC 281 282 Wire.beginTransmission(0x68); 283 // adress RTC DS1307 or DS3231 284 Wire.write(adres); // address register 285 DS3231 286 Wire.endTransmission(); // einde I2C routine 287 Wire.requestFrom(0x68, 288 1); 289 return Wire.read(); 290} 291//------------------------------------------------------------------------ 292void 293 instelroutine(byte adres, byte data1) {// set register of RTC 294 Wire.beginTransmission(0x68); 295 // adress RTC DS3231 296 Wire.write(adres); // address register DS3231 297 298 Wire.write(data1); 299 Wire.endTransmission(); // einde I2C routine 300} 301//------------------------------------------------------------------------ 302byte 303 decToBcd(byte val) { 304 return ((val / 10 * 16) + (val % 10)); 305} 306//------------------------------------------------------------------------ 307void 308 Agingadjust(byte data1) {// fine adjust the frequency of the RTC 309 310 instelroutine(16, 311 data1); 312 /* 313 Positive aging values add capacitance to the array, slowing 314 the 315 oscillator frequency. Negative values remove capacitance from 316 the array, 317 increasing the oscillator frequency. The change in ppm per LSB 318 is different 319 at different temperatures. The frequency vs. temperature curve 320 is shifted by 321 the values used in this registert. At +25C, one LSB 322 typically 323 provides about 0.1ppm change in frequency. 324 */ 325} 326//------------------------------------------------------------------------ 327void 328 SQW1hzOn() {// switch the 1 Hz SQW on 329 instelroutine(14, 0); 330} 331//------------------------------------------------------------------------ 332void 333 zet_jaar(byte data1) { // set year 334 instelroutine(6, decToBcd(data1)); 335} 336//------------------------------------------------------------------------ 337void 338 zet_maand(byte data1) { // set month 339 instelroutine(5, decToBcd(data1)); 340} 341//------------------------------------------------------------------------ 342void 343 zet_datum(byte data1) { // set day of month 344 instelroutine(4, decToBcd(data1)); 345} 346//------------------------------------------------------------------------ 347void 348 zet_dagweek(byte data1) { // set DOW 349 instelroutine(3, decToBcd(data1)); 350} 351//------------------------------------------------------------------------ 352void 353 zet_uur(byte data1) { // set hour 354 instelroutine(2, decToBcd(data1)); 355} 356//------------------------------------------------------------------------ 357void 358 zet_minuut(byte data1) { // set minute 359 instelroutine(1, decToBcd(data1)); 360} 361//------------------------------------------------------------------------ 362void 363 zet_seconde(byte data1) { // set second 364 instelroutine(0, decToBcd(data1)); 365} 366//---------------------------------------------------------- 367void 368 TijdUitlezen() { 369 second = lees_seconde(); 370 minute = lees_minuut(); 371 372 hour = lees_uur(); 373 weekday = lees_dagweek(); //0-6 -> sunday - Saturday 374 375 monthDay = lees_datum(); 376 month = lees_maand(); 377 year = lees_jaar(); 378 379 // Serial.println(year); 380 Sjaar = year; 381 // seconde uitlezen/// 382 Factor(second, 383 false); 384 a = EH; 385 b = TT; 386 Factor(minute, false); 387 c = EH; 388 d 389 = TT; 390 // uur uitlezen/// 391 Factor(hour, false); 392 e = EH; 393 f = TT; 394 395 396 // dag uitlezen/// 397 Factor(monthDay, false); 398 g = EH; 399 h = TT; 400 401 402 // maand uitlezen/// 403 Factor(month, false); 404 i = EH; 405 j = TT; 406 407 408 // jaar uitlezen/// 409 Factor(year, false); 410 k = EH; 411 m = TT; 412 413 414 //Serial.println(second); 415} 416// -------------------------------------------------------- 417void 418 Schrikkeljaar() { 419 420 Sjaar %= 4; // %= is remainder -------- 421 422 if 423 (Sjaar == 0) { 424 Schrikkel = 1; 425 Lentepunt = 81; 426 Dagen = 366; 427 428 } else { 429 Schrikkel = 0; 430 Lentepunt = 80; 431 Dagen = 365; 432 433 } 434} 435 436// ------------------------------------------------------------------ 437void 438 showDirection(Rotary& rt) { 439 //Serial.println(rt.getDirection()); 440 441 counter 442 = rt.getDirection(); 443 if (counter == 255) 444 { 445 counter = -1; 446 } 447 448 else 449 { 450 counter = 1; 451 } 452 encoderPos += counter; 453 //Serial.println(encoderPos); 454} 455 456 457//-------------------------------------------------------- 458void 459 pressed(Button2& btn) { 460 //Serial.print("pressed "); 461 buttonPressed = 462 1; 463 //Serial.println(buttonPressed); 464} 465void released(Button2& btn) { 466 467 // Serial.print("released: "); 468 buttonPressed = 0; 469 //Serial.println(buttonPressed); 470} 471 472//--------------------------------------------- 473 474 475void 476 Factor(long Getal, bool graden) { 477 long Test; 478 //Serial.println(Getal); 479 480 Test = Getal; 481 HDT = Test / 100000; 482 Test = Test - (HDT * 100000); 483 484 485 TDT = Test / 10000; 486 Test = Test - (TDT * 10000); 487 488 DT = Test / 1000; 489 490 Test = Test - (DT * 1000); 491 492 493 HT = Test / 100; 494 Test = Test - (HT 495 * 100); 496 497 if (graden == true) {// if true : decimaal to degree conversion 498 499 Test = Test * 0.6; 500 } 501 TT = Test / 10; 502 Test = Test - (TT * 10); 503 504 505 EH = Test; 506} 507//-------------------------------------------------------------------------------- 508void 509 secondsRTC(void) { // *** ISR iedere seconde *** 510 secondsInterrupt = 1; // 511 ISR vlag = 1 : er was een 'seconds' interrupt. 512} 513//------------------------------------------------------------------------ 514void 515 readtime() { 516 517 second = lees_seconde();// read seconds 518 // seconde uitlezen/// 519 520 Factor(second, false); 521 a = EH; 522 b = TT; 523 524 if (second == 0) { 525 526 minute = lees_minuut();// read minutes 527 // minuut uitlezen/// 528 Factor(minute, 529 false); 530 c = EH; 531 d = TT; 532 } 533 534 if (minute == 0 & second == 535 0) { 536 hour = lees_uur();// read hour 537 // uur uitlezen/// 538 Factor(hour, 539 false); 540 e = EH; 541 f = TT; 542 } 543 544 if (hour == 0 & second == 545 0) { 546 weekday = lees_dagweek(); //0-6 -> sunday - Saturday 547 monthDay 548 = lees_datum();// read day of month 549 month = lees_maand();// read month 550 551 year = lees_jaar();// read year 552 553 // dag uitlezen/// 554 Factor(monthDay, 555 false); 556 g = EH; 557 h = TT; 558 // maand uitlezen/// 559 Factor(month, 560 false); 561 i = EH; 562 j = TT; 563 Factor(year, false); 564 k = EH; 565 566 m = TT; 567 } 568} 569//--------------------------------------------------------- 570void 571 loop() { 572 test1 = digitalRead(SW1); // read the switch 573 test2 = digitalRead(SW2); 574 575 test3 = digitalRead(SW3); 576 test4 = digitalRead(SW4); 577 Test = test4 * 8; 578 579 Test += test3 * 4; 580 Test += test2 * 2; 581 Test += test1; 582 583 584 if 585 (secondsInterrupt == 1) { // **** doe als ISR vlag = 1 **** 586 readtime(); 587 // de subroutine die iedere seconde de tijd registers leest. 588 589 if (Test == 4) { 590 Reset60Led(); 591 } else { 592 Led60AanSturen();// 593 update 60 + 12 leds 594 } 595 secondsInterrupt = 0; // zet ISR vlag terug 596 naar '0' 597 } 598 599 switch (Test) { 600 case 15: //1111 601 602 digitalWrite(DecPunt, 1); // DecPunt = display dot >> 1 = ON and 0 = OFF 603 604 LEDDisplayBLANK(); // regel 872 605 break; 606 case 14: //1110 607 608 digitalWrite(DecPunt, 1); 609 LedTijd(); // time 610 break; 611 612 case 13: //1101 613 digitalWrite(DecPunt, 1); 614 Leddatum(); // 615 date 616 break; 617 case 12: //1100 618 digitalWrite(DecPunt, 0); 619 620 LCDAzimuth(); // elevation of the sun 621 break; 622 case 11: //1011 623 624 digitalWrite(DecPunt, 1); 625 LedSeconde(); // seconds 626 break; 627 628 case 10: //1010 629 digitalWrite(DecPunt, 1); 630 DagNR(); // amount 631 of days since januari first 632 break; 633 case 9: //1001 634 digitalWrite(DecPunt, 635 1); 636 Zonsopgang(); // sun rise 637 break; 638 case 8: //1000 639 640 digitalWrite(DecPunt, 1); 641 LedDOW(); // Dau Of Week 642 break; 643 644 case 7: //0111 645 digitalWrite(DecPunt, 1); 646 Ledjaar(); // year 647 648 break; 649 case 6: //0110 650 digitalWrite(DecPunt, 0); 651 DagDuur(); 652 // Length of day in hours 653 break; 654 case 5: //0101 655 digitalWrite(DecPunt, 656 0); 657 SchStand(); // tilt of earth 658 break; 659 case 4: //0100 660 661 digitalWrite(DecPunt, 1); 662 Adjust(); // adjust 663 break; 664 665 case 3: //0011 666 digitalWrite(DecPunt, 0); 667 LedMaanOuderdom(); 668 // moon age in days 669 break; 670 case 2: //0010 671 digitalWrite(DecPunt, 672 1); 673 DagSEC(); // seconds since midnight 674 break; 675 case 1: 676 //0001 677 digitalWrite(DecPunt, 1); 678 Zonsondergang(); // sun set 679 680 break; 681 case 0: //0000 682 digitalWrite(DecPunt, 0); 683 HzonNU(); 684 // present elevation of the sun 685 break; 686 } 687} 688// -------------end 689 loop ----------------------- 690//------------------------------------------------------------------------------------ 691 692void 693 Adjust() { 694 695 rt.loop(); 696 bt.loop(); 697 if (encoderPos < 0) { 698 encoderPos 699 = 0; 700 } 701 if (encoderPos > 8) { 702 encoderPos = 8; 703 } 704 switch 705 (encoderPos) { 706 case 0: 707 DisplayAjust(); 708 break; 709 case 710 1: 711 Displaykeuze1(64); 712 if (encoderPos == 1 && buttonPressed == 713 1) { 714 encoderPos = 0; 715 AdjustUUR(); 716 } 717 break; 718 719 case 2: 720 DisplaykeuzeWT(64); 721 if (encoderPos == 2 && buttonPressed 722 == 1) { 723 encoderPos = 0; 724 AdjustWT(); 725 } 726 break; 727 728 case 3: 729 Displaykeuze3(64); 730 if (encoderPos == 3 && buttonPressed 731 == 1) { 732 encoderPos = 0; 733 AdjustMIN(); 734 } 735 break; 736 737 case 4: 738 Displaykeuze4(64); 739 if (encoderPos == 4 && buttonPressed 740 == 1) { 741 encoderPos = 0; 742 AdjustDAG(); 743 } 744 break; 745 746 case 5: 747 Displaykeuze5(64); 748 if (encoderPos == 5 && buttonPressed 749 == 1) { 750 encoderPos = 0; 751 AdjustMND(); 752 } 753 break; 754 755 case 6: 756 Displaykeuze6(64); 757 if (encoderPos == 6 && buttonPressed 758 == 1) { 759 encoderPos = 0; 760 AdjustYR(); 761 } 762 break; 763 764 case 7: 765 Displaykeuze7(64); 766 if (encoderPos == 7 && buttonPressed 767 == 1) { 768 encoderPos = 0; 769 AdjustDOW(); 770 } 771 break; 772 773 case 8: 774 AR = AgingRead(); 775 Displaykeuze8(AR); 776 if (encoderPos 777 == 8 && buttonPressed == 1) { 778 encoderPos = 0; 779 AdjustAging(); 780 781 } 782 break; 783 } 784} 785 786// ------------------------------------------------------ 787void 788 DisplayAjust() { 789 DDMM(120, 109, 30, 94, 119); 790} 791 792//------------------------------------------------------------- 793void 794 AdjustUUR() { 795 int exx = 0; 796 Displaykeuze1(73); 797 encoderPos = 0; 798 799 buttonPressed = 0; 800 while (exx == 0) { 801 rt.loop(); 802 bt.loop(); 803 804 if (encoderPos == 0) { 805 Factor(hour, false); 806 e = EH; 807 f 808 = TT; 809 Displaykeuze1(64); // uur 810 } 811 //----------------- 812 813 814 if (encoderPos > 1) { 815 hour = hour + 1; 816 if (hour == 24) { 817 818 hour = 0; 819 } 820 Factor(hour, false); 821 e = EH; 822 823 f = TT; 824 Displaykeuze1(1); // uur 825 encoderPos = 1; 826 } 827 828 829 // -------------------------- 830 if (encoderPos < -1) { 831 hour = 832 hour - 1; 833 if (hour < 0) { 834 hour = 23; 835 } 836 837 Factor(hour, 838 false); 839 e = EH; 840 f = TT; 841 Displaykeuze1(8); // uur 842 843 encoderPos = -1; 844 } 845 if (buttonPressed == 1 & encoderPos != 0) 846 { 847 zet_uur(hour);// set hour 848 Displaykeuze1(9); // uur 849 encoderPos 850 = 0; 851 exx = 1; 852 } 853 854 } 855} 856 857 858// ------------------------------------------------------ 859void 860 Displaykeuze1(int x) { 861 DDMM(segCode[e], segCode[f], x, 80, 116); 862} 863//------------------------------------------------------------- 864void 865 AdjustWT() {//daylight saving time >> 1 = summer time, 0 = winter time 866 int 867 exx = 0; 868 encoderPos = 0; 869 buttonPressed = 0; 870 DisplaykeuzeWT(73); 871 872 while (exx == 0) { 873 rt.loop(); 874 bt.loop(); 875 if (encoderPos == 876 0) { 877 DisplaykeuzeWT(64); 878 } 879 //----------------- 880 881 882 883 if (encoderPos > 1) { 884 WT = 1; 885 DisplaykeuzeWT(1); 886 encoderPos 887 = 1; 888 } 889 890 891 // -------------------------- 892 if (encoderPos 893 < -1) { 894 895 WT = 0; 896 DisplaykeuzeWT(8); 897 encoderPos = -1; 898 899 } 900 if (buttonPressed == 1 & encoderPos != 0) { 901 DisplaykeuzeWT(9); 902 903 encoderPos = 0; 904 exx = 1; 905 } 906 } 907} 908 909 910// ------------------------------------------------------ 911void 912 DisplaykeuzeWT(int x) { 913 DDMM(segCode[WT], 0, x, 120, 120); 914} 915//----------------------------------------------------------- 916void 917 AdjustMIN() { 918 int exx = 0; 919 Displaykeuze3(73); 920 encoderPos = 0; 921 922 buttonPressed = 0; 923 while (exx == 0) { 924 925 rt.loop(); 926 bt.loop(); 927 928 if (encoderPos == 0) { 929 Displaykeuze3(64); // min 930 } 931 //----------------- 932 933 934 935 if (encoderPos > 1) { 936 minute = minute + 1; 937 if (minute == 60) 938 { 939 minute = 0; 940 } 941 Factor(minute, false); 942 c = 943 EH; 944 d = TT; 945 Displaykeuze3(1); // min 946 encoderPos = 1; 947 948 } 949 950 // -------------------------- 951 if (encoderPos < -1) { 952 953 minute = minute - 1; 954 if (minute < 0) { 955 minute = 59; 956 957 } 958 Factor(minute, false); 959 c = EH; 960 d = TT; 961 Displaykeuze3(8); 962 // uur 963 encoderPos = -1; 964 } 965 if (buttonPressed == 1 & encoderPos 966 != 0) { 967 zet_seconde(0);// set second 968 zet_minuut(minute);// set 969 minute 970 Displaykeuze3(9); // min 971 encoderPos = 0; 972 exx 973 = 1; 974 } 975 976 } 977} 978 979// ------------------------------------------------------ 980void 981 Displaykeuze3(int x) { 982 DDMM(segCode[c], segCode[d], x, 84, 55); 983} 984 985//---------------------------------------------------------- 986void 987 AdjustDAG() { 988 int exx = 0; 989 Displaykeuze4(73); 990 encoderPos = 0; 991 992 buttonPressed = 0; 993 while (exx == 0) { 994 995 rt.loop(); 996 bt.loop(); 997 998 if (encoderPos == 0) { 999 Displaykeuze4(64); // min 1000 } 1001 //----------------- 1002 1003 1004 1005 if (encoderPos > 1) { 1006 monthDay = monthDay + 1; 1007 if (monthDay 1008 == 32) { 1009 monthDay = 1; 1010 } 1011 Factor(monthDay, false); 1012 1013 g = EH; 1014 h = TT; 1015 Displaykeuze4(1); // min 1016 encoderPos 1017 = 1; 1018 } 1019 // -------------------------- 1020 if (encoderPos < -1) { 1021 1022 monthDay = monthDay - 1; 1023 if (monthDay == 0) { 1024 monthDay 1025 = 31; 1026 } 1027 1028 Factor(monthDay, false); 1029 g = EH; 1030 h 1031 = TT; 1032 Displaykeuze4(8); // uur 1033 encoderPos = -1; 1034 } 1035 1036 if (buttonPressed == 1 & encoderPos != 0) { 1037 zet_datum(monthDay);// 1038 set monthday 1039 Displaykeuze4(9); // min 1040 encoderPos = 0; 1041 buttonPressed 1042 = 0; 1043 exx = 1; 1044 } 1045 1046 } 1047} 1048// ------------------------------------------------------ 1049void 1050 Displaykeuze4(int x) { 1051 DDMM(segCode[g], segCode[h], x, 110, 94); 1052} 1053 1054//------------------------------------------------------- 1055void 1056 AdjustMND() { 1057 int exx = 0; 1058 Displaykeuze5(73); 1059 encoderPos = 0; 1060 1061 buttonPressed = 0; 1062 while (exx == 0) { 1063 1064 rt.loop(); 1065 bt.loop(); 1066 1067 1068 if (encoderPos == 0) { 1069 Displaykeuze5(64); 1070 } 1071 //----------------- 1072 1073 1074 1075 if (encoderPos > 1) { 1076 month = month + 1; 1077 if (month > 12) { 1078 1079 month = 1; 1080 } 1081 Factor(month, false); 1082 i = EH; 1083 1084 j = TT; 1085 Displaykeuze5(1); 1086 encoderPos = 1; 1087 } 1088 // 1089 -------------------------- 1090 if (encoderPos < -1) { 1091 month = month 1092 - 1; 1093 if (month == 0) { 1094 month = 12; 1095 } 1096 1097 Factor(month, 1098 false); 1099 i = EH; 1100 j = TT; 1101 Displaykeuze5(8); 1102 encoderPos 1103 = -1; 1104 } 1105 if (buttonPressed == 1 & encoderPos != 0) { 1106 zet_maand(month);// 1107 set month 1108 Displaykeuze5(9); 1109 encoderPos = 0; 1110 exx = 1; 1111 1112 } 1113 1114 } 1115} 1116// ------------------------------------------------------ 1117void 1118 Displaykeuze5(int x) { 1119 DDMM(segCode[i], segCode[j], x, 94, 55); 1120} 1121 1122//------------------------------------------------------ 1123void 1124 AdjustYR() { 1125 int exx = 0; 1126 encoderPos = 0; 1127 buttonPressed = 0; 1128 1129 Displaykeuze6(73); 1130 if (year > 2000) { 1131 year = year - 2000; 1132 } 1133 1134 while (exx == 0) { 1135 1136 rt.loop(); 1137 bt.loop(); 1138 1139 if (encoderPos 1140 == 0) { 1141 Displaykeuze6(64); // min 1142 } 1143 //----------------- 1144 1145 1146 1147 if (encoderPos > 1) { 1148 year = year + 1; 1149 if (year > 99) { 1150 1151 year = 0; 1152 } 1153 Factor(year, false); 1154 k = EH; 1155 1156 m = TT; 1157 Displaykeuze6(1); // min 1158 encoderPos = 1; 1159 } 1160 1161 // -------------------------- 1162 if (encoderPos < -1) { 1163 year = 1164 year - 1; 1165 if (year < 0) { 1166 year = 99; 1167 } 1168 Factor(year, 1169 false); 1170 k = EH; 1171 m = TT; 1172 Displaykeuze6(8); // uur 1173 1174 encoderPos = -1; 1175 } 1176 if (buttonPressed == 1 & encoderPos != 0) 1177 { 1178 zet_jaar(year);// set year 1179 Displaykeuze6(9); // min 1180 encoderPos 1181 = 0; 1182 exx = 1; 1183 } 1184 1185 } 1186} 1187// ------------------------------------------------------ 1188void 1189 Displaykeuze6(int x) { 1190 DDMM(segCode[k], segCode[m], x, 80, 110); 1191} 1192//------------------------------------------------------ 1193void 1194 AdjustDOW() { 1195 int exx = 0; 1196 encoderPos = 0; 1197 buttonPressed = 0; 1198 1199 Displaykeuze7(73); 1200 1201 while (exx == 0) { 1202 1203 rt.loop(); 1204 bt.loop(); 1205 1206 if (encoderPos == 0) { 1207 Displaykeuze7(64); // 1208 } 1209 //----------------- 1210 1211 1212 1213 if (encoderPos > 1) { 1214 weekday = weekday + 1; 1215 if (weekday > 1216 7) { 1217 weekday = 7; // 1 = maandag , 2 = dinsdag enz. 1218 } 1219 1220 1221 Displaykeuze7(1); // 1222 encoderPos = 1; 1223 } 1224 1225 // -------------------------- 1226 1227 if (encoderPos < -1) { 1228 weekday = weekday - 1; 1229 if (weekday 1230 < 1) { 1231 weekday = 1; 1232 } 1233 1234 Displaykeuze7(8); // 1235 1236 encoderPos = -1; 1237 } 1238 if (buttonPressed == 1 & encoderPos != 0) 1239 { 1240 zet_dagweek(weekday);// setDOW 1241 Displaykeuze7(9); // 1242 encoderPos 1243 = 0; 1244 exx = 1; 1245 } 1246 1247 } 1248} 1249// ------------------------------------------------------ 1250void 1251 Displaykeuze7(int x) { 1252 DDMM(segCode[weekday], x, 110, 119, 94); 1253} 1254//------------------------------------------------------ 1255void 1256 AdjustAging() { 1257 int exx = 0; 1258 encoderPos = 0; 1259 buttonPressed = 0; 1260 1261 1262 Displaykeuze8(AR); 1263 1264 AR = AgingRead(); 1265 1266 while (exx == 0) { 1267 1268 Displaykeuze8(AR); 1269 rt.loop(); 1270 bt.loop(); 1271 1272 1273 if (encoderPos 1274 == 0) { 1275 Displaykeuze8(AR); 1276 1277 } 1278 //----------------- 1279 1280 1281 if (encoderPos > 1) { 1282 AR = AR + 1; 1283 if (AR > 127) { 1284 AR 1285 = 0; 1286 } 1287 1288 Displaykeuze8(AR); 1289 encoderPos = 1; 1290 } 1291 1292 1293 // -------------------------- 1294 if (encoderPos < -1) { 1295 AR = AR 1296 - 1; 1297 if (AR < -128) { 1298 AR = 0; 1299 } 1300 1301 Displaykeuze8(AR); 1302 1303 encoderPos = -1; 1304 } 1305 if (buttonPressed == 1 & encoderPos != 0) 1306 { 1307 Agingadjust(AR); 1308 Displaykeuze8(AR); 1309 encoderPos = 0; 1310 1311 buttonPressed = 0; 1312 exx = 1; 1313 } 1314 1315 } 1316} 1317// ------------------------------------------------------ 1318void 1319 Displaykeuze8(byte ARR) { 1320 int RR; 1321 // aging register of RTC uses two's 1322 complement, a negative number is from 128 to 255 1323 RR = ARR; 1324 1325 if (RR 1326 >= 0 & RR < 128) { 1327 Factor(RR, false); 1328 DDMM(segCode[EH], segCode[TT], 1329 segCode[HT], 0, 119); 1330 } 1331 else 1332 { 1333 RR = RR - 256; 1334 RR = 1335 abs(RR); 1336 Factor(RR, false); 1337 DDMM(segCode[EH], segCode[TT], segCode[HT], 1338 64, 119); 1339 } 1340 1341} 1342//---------------------------------------------- 1343void 1344 pulseCLK() { 1345 digitalWrite(CLK, 1); 1346 digitalWrite(CLK, 0); 1347} 1348//------------------------------------------------- 1349void 1350 pulseCLKMM() { 1351 digitalWrite(CLKMM, 1); 1352 digitalWrite(CLKMM, 0); 1353} 1354//------------------------------------------------------------- 1355// 1356 LSB out first! 1357void ssrWriteLSB(byte value) { 1358 for (int x = 0; x < 5; x++) 1359 { 1360 byte temp = value & 0x01; 1361 if (temp == 0x01) { 1362 digitalWrite(dataBit, 1363 1); // data bit HIGH 1364 } else { 1365 digitalWrite(dataBit, 0); // data 1366 bit LOW 1367 } 1368 pulseCLK(); 1369 value = value >> 0x01; // shift right 1370 1371 } 1372} 1373//---------------------------------------------------------- 1374void 1375 DDMM(byte D1, byte D2, byte D3, byte D4, byte D5) { 1376 digitalWrite(dataBitMM, 1377 1); 1378 pulseCLKMM(); 1379 ssrWriteLSBMM(D1); 1380 ssrWriteLSBMM(D2); 1381 ssrWriteLSBMM(D3); 1382 1383 ssrWriteLSBMM(D4); 1384 ssrWriteLSBMM(D5); 1385 zeroWrite(1); // pad remaining 1386 bits with 0s (35-35)+1 1387} 1388//---------------------------------------------------------- 1389void 1390 ssrWriteLSBMM(byte value) { 1391 for (int x = 0; x < 7; x++) { 1392 byte temp 1393 = value & 0x01; 1394 if (temp == 0x01) { 1395 digitalWrite(dataBitMM, 1); 1396 // data bit HIGH 1397 } else { 1398 digitalWrite(dataBitMM, 0); // data 1399 bit LOW 1400 } 1401 pulseCLKMM(); 1402 value = value >> 0x01; // shift right 1403 1404 } 1405} 1406//------------------------------------------------------------------ 1407// 1408 MSB out first! 1409void ssrWriteMSB(byte value) { 1410 for (int x = 0; x < 5; x++) 1411 { 1412 byte temp = value & 0x80; 1413 if (temp == 0x80) digitalWrite(dataBit, 1414 1); // data bit HIGH 1415 else 1416 digitalWrite(dataBit, 0); // data bit 1417 LOW 1418 pulseCLK(); 1419 value = value << 0x01; // shift left 1420 } 1421} 1422//--------------------------------------------------------- 1423void 1424 zeroWrite(byte num1) { 1425 digitalWrite(dataBitMM, 0); // data bit LOW 1426 for 1427 (int x = 0; x < num1; x++) 1428 pulseCLKMM(); 1429} 1430//--------------------------------------------------------- 1431void 1432 LedSeconde() { 1433 DDMM(segCode[a], segCode[b], 64, 64, 64); 1434} 1435//-------------------------------------------------------- 1436void 1437 LedTijd() { 1438 int test = second; 1439 test %= 2; //%= is remainder ---- 1440 1441 if (test == 1) { 1442 DDMM(segCode[c], segCode[d], 9, segCode[e], segCode[f]); 1443 1444 } else { 1445 DDMM(segCode[c], segCode[d], 64, segCode[e], segCode[f]); 1446 1447 } 1448} 1449//----------------------------------------------------------------- 1450void 1451 Led60AanSturen() { 1452 SecondenAansturen();// update seconds 1453 if (second == 1454 0) { 1455 MinutenAanSturen();// update minutes 1456 } 1457 if (minute == 0 & second 1458 == 0) { 1459 UrenAansturen();// update hours 1460 LEDMaan();// update moon 1461 1462 } 1463 if (CodeLedMS[0] == 0 & CodeLedMS[1] == 0 & CodeLedMS[2] == 0) { 1464 MinutenAanSturen(); 1465 1466 UrenAansturen(); 1467 LEDMaan(); 1468 } 1469 1470 CodeOR(); 1471 1472 digitalWrite(Latch, 1473 1); 1474 for (int x = 0; x < 15; x++) { 1475 ssrWriteLSB(CodeLedMS[x]); 1476 } 1477 1478 digitalWrite(Latch, 0); 1479} 1480//--------------------------------------------------------------- 1481 1482void 1483 SecondenAansturen() { 1484 // b = seconds tenth 1485 //a = seconds unity 1486 1487 1488 for (byte x = 0; x < 15; x++) { 1489 CodeSec[x] = 0; // 15 nullen in codeSec 1490 zetten 1491 } 1492 1493 // a = 0 .... 9 1494 // b = 0,1,2,3,4 or 5 1495 // cc = segment 1496 14 t/m 3 1497 //segment 14 = led 0 t/m 4, segment 13 = led 5 t/m 9 1498 //segment 1499 12 = led 10 t/m 14, segment 11 = led 15 t/m 19 1500 //segment 10 = led 20 t/m 24, 1501 segment 9 = led 25 t/m 29 1502 //segment 8 = led 30 t/m 34, segment 7 = led 35 t/m 1503 39 1504 //segment 6 = led 40 t/m 44, segment 5 = led 45 t/m 49 1505 //segment 4 1506 = led 50 t/m 54, segment 3 = led 55 t/m 59 1507 //b=0, led 0 t/m 9, 1508 //b=1, 1509 led 10 t/m 19 1510 //b=2, led 20 t/m 29 1511 //b=3, led 30 t/m 39 1512 //b=4, led 1513 40 t/m 49 1514 //b=5, led 50 t/m 59 1515 1516 cc = 14 - (b * 2); 1517 if (a < 5) 1518 { 1519 CodeSec[cc] = bindec[a]; 1520 } else { 1521 CodeSec[cc - 1] = bindec[a]; 1522 1523 } 1524 1525 /* 1526 switch (b)// b = seconden tientallen 1527 { 1528 case 1529 0:// ------ van 0 tot/m 9 seconden---------------- 1530 if (a < 5) // a 1531 = seconden eenheden 1532 { 1533 CodeSec[14] = bindec[a]; //1 x 1534 data 1535 } 1536 else 1537 { 1538 CodeSec[13] = bindec[a]; 1539 //1 x data 1540 } 1541 break; 1542 1543 case 1: // van 10 1544 tot/m 19 seconden------------------------ 1545 if (a < 5) // a = seconden 1546 eenheden 1547 { 1548 CodeSec[12] = bindec[a]; //1 x data 1549 } 1550 1551 else 1552 { 1553 CodeSec[11] = bindec[a]; //1 x data 1554 1555 } 1556 break; 1557 1558 case 2: // van 20 tot 29 seconden-------------------- 1559 1560 if (a < 5) // a = seconden eenheden 1561 { 1562 CodeSec[10] 1563 = bindec[a]; //1 x data 1564 } 1565 else 1566 { 1567 CodeSec[9] 1568 = bindec[a]; //1 x data 1569 } 1570 break; 1571 1572 case 3:// 1573 van 30 tot 39 seconden--------------------- 1574 if (a < 5) // a = seconden 1575 eenheden 1576 { 1577 CodeSec[8] = bindec[a]; //1 x data 1578 } 1579 1580 else 1581 { 1582 CodeSec[7] = bindec[a]; //1 x data 1583 1584 } 1585 break; 1586 1587 case 4: // van 40 tot 49 seconden------------------------- 1588 1589 if (a < 5) // a = seconden eenheden 1590 { 1591 CodeSec[6] 1592 = bindec[a]; //1 x data 1593 } 1594 else 1595 { 1596 CodeSec[5] 1597 = bindec[a]; //1 x data 1598 } 1599 break; 1600 1601 case 5: 1602 // van 50 tot 59 seconden------------------------- 1603 if (a < 5) // 1604 a = seconden eenheden 1605 { 1606 CodeSec[4] = bindec[a]; //1 x 1607 data 1608 } 1609 else 1610 { 1611 CodeSec[3] = bindec[a]; 1612 //1 x data 1613 } 1614 break; 1615 } 1616 */ 1617} 1618 1619//----------------------------------------------------------------------------------- 1620void 1621 MinutenAanSturen() { 1622 1623 for (byte x = 0; x < 15; x++) { 1624 CodeMin[x] 1625 = 0; // 15 nullen in codeMin zetten 1626 } 1627 // d = 0,1,2,3,4 of 5 1628 //cc 1629 = ledcode[d]; 1630 cc = 14 - (d * 2); 1631 if (c < 5) { 1632 CodeMin[cc] = bindec[c]; 1633 1634 } else { 1635 CodeMin[cc - 1] = bindec[c]; 1636 } 1637} 1638//----------------------------------------------------------------------- 1639 1640void 1641 UrenAansturen() { 1642 1643 byte ee; 1644 byte ff; 1645 byte uur; 1646 uur = hour; 1647 1648 //uur = 0; 1649 1650 if (uur >= 12) { 1651 uur = uur - 12; 1652 } 1653 // uur 1654 uitlezen/// 1655 Factor(uur, false); 1656 ee = EH; // eenheden 1657 ff = TT; // 1658 tientallen 1659 //f=1; 1660 //e=1; 1661 CodeLedMS[0] = 0; 1662 CodeLedMS[1] = 0; 1663 1664 CodeLedMS[2] = 0; 1665 1666 switch (ff) { 1667 case 0: 1668 if (ee < 5) // 1669 ee = uren eenheden 1670 { 1671 CodeLedMS[2] = bindec[ee]; //1 x data 1672 1673 } else { 1674 CodeLedMS[1] = bindec[ee]; //1 x data 1675 } 1676 1677 break; 1678 case 1: 1679 CodeLedMS[0] = bindec[ee]; //1 x data 1680 1681 break; 1682 } 1683} 1684 1685//-------------------------------------------------------------- 1686void 1687 CodeOR() { 1688 1689 for (byte aa = 3; aa < 15; aa++) { 1690 // minuten met seconden 1691 OR bewerking ------------------------------ 1692 CodeLedMS[aa] = CodeMin[aa] 1693 | CodeSec[aa]; // "|" = OR functie 1694 } 1695 1696 switch (Test) { 1697 case 1698 15: //1111 1699 // do nothing 1700 break; 1701 default: 1702 byte 1703 testsec = second; 1704 testsec %= 2; 1705 if (testsec == 0) { 1706 // 1707 minuten en seconden met maan OR bewerking ------------------- 1708 for (byte 1709 aa = 3; aa < 15; aa++) { 1710 CodeLedMS[aa] = Codemaan[aa] | CodeLedMS[aa]; 1711 1712 } 1713 } 1714 break; 1715 } 1716 1717 1718 1719 //for (int x = 0; x 1720 < 15; x++) { 1721 // Serial.print("CodeMS: "); 1722 // Serial.print(x); 1723 1724 // Serial.print(" "); 1725 // Serial.println(CodeLedMS[x]); 1726 // } 1727} 1728//-------------------------------------------------------------- 1729 1730void 1731 Reset60Led() { 1732 for (byte x = 0; x < 15; x++) { 1733 CodeLedMS[x] = 0; 1734 1735 } 1736 for (byte x = 0; x < 15; x++) { 1737 ssrWriteLSB(CodeLedMS[x]); 1738 } 1739} 1740// 1741 --------------------------------------------------------------------- 1742void Led60Test() 1743 { 1744 1745 byte aa; 1746 byte bb; 1747 byte cc1; 1748 for (byte x = 0; x < 60; x++) 1749 { 1750 Factor(x, false); 1751 aa = EH; 1752 bb = TT; 1753 cc1 = 14 - (bb 1754 * 2); 1755 if (aa < 5) { 1756 CodeLedMS[cc1] = bindec[aa]; 1757 } else { 1758 1759 CodeLedMS[cc1 - 1] = bindec[aa]; 1760 } 1761 digitalWrite(Latch, 1); 1762 1763 for (int xx = 3; xx < 15; xx++) { 1764 ssrWriteLSB(CodeLedMS[xx]); 1765 } 1766 1767 digitalWrite(Latch, 0); 1768 delay(100); 1769 for (byte x = 0; x < 15; x++) 1770 { 1771 CodeLedMS[x] = 0; // 15 nullen in codeledMS zetten 1772 } 1773 } 1774 1775} 1776//-------------------------------------------------------------- 1777void 1778 Leddatum() { 1779 DDMM(segCode[i], segCode[j], 64, segCode[g], segCode[h]); 1780} 1781// 1782 --------------------------------------------------------- 1783void Ledjaar() { 1784 1785 DDMM(segCode[k], segCode[m], segCode[0], segCode[2], segCode[16]); 1786} 1787//------------------------------------------------------------ 1788void 1789 LedDOW() { 1790 DDMM(segCode[weekday], segCode2[5], segCode2[4], segCode2[3], segCode2[2]); 1791} 1792//-------------------------------------------------------------- 1793void 1794 LedMaanOuderdom() { 1795 LEDMaan(); 1796 float Oud; 1797 Oud = MoonAge; 1798 1799 1800 Factor(Oud * 100, false); 1801 DDMM(segCode[EH], segCode[TT], segCode[HT], segCode[DT], 1802 segCode2[6]); 1803} 1804 1805// ----------------------------------------------------------- 1806void 1807 LEDDisplayBLANK() { 1808 DDMM(segCode[16], segCode[16], segCode[16], segCode[16], 1809 segCode[16]); 1810} 1811 1812//-------------------------------------------------------------- 1813byte 1814 segCode1[24] = { 1815 0b0000001, 0b0000010, 0b0000100, 1816 0b0001000, 0b0010000, 1817 0b0100000, 1818 0b1000000, 0b1001001, 0b1000000, 1819 0b1001001, 0b1000000, 0b1001001, 1820 1821 0b1000000, 0b0111111, 0b0000110, 1822 0b1011011, 0b1001111, 0b1100110, 1823 0b1101101, 1824 0b1111101, 0b0000111, 1825 0b1111111, 0b1101111, 0b1110110 1826}; 1827//-------------------------------------------------------------- 1828void 1829 Displaytest() { 1830 1831 // start bit 1832 for (int x = 0; x < 23; x++) { 1833 DDMM(segCode1[x], 1834 segCode1[x], segCode1[x], segCode1[x], segCode1[x]); 1835 delay(300); 1836 } 1837 1838 delay(1000); 1839} 1840 1841//----------------------------------------------------------------- 1842void 1843 LEDMaan() { 1844 float Uur1; 1845 float Min1; 1846 float MOud; 1847 int Index; 1848 1849 float AZ; 1850 int v = 0; 1851 int w = 0; 1852 int Jaar; 1853 Schrikkeljaar(); 1854 1855 AZ = TotaalDagen(month); 1856 Min1 = minute; 1857 Uur1 = hour + (Min1 / 60); 1858 1859 AZ = AZ + monthDay; 1860 AZ = AZ + (Uur1 / 24); 1861 Jaar = year; 1862 if (year 1863 > 2000) { 1864 year = year - 2000; 1865 } 1866 Index = year - 17; // epactagetal 1867 ophalen 1868 while (Index > 18) { 1869 Index = Index - 19; 1870 } 1871 1872 //Serial.println(Index); 1873 1874 MOud = Maan[Index]; 1875 //Serial.println(MOud); 1876 MOud = MOud + AZ; 1877 //Serial.println(MOud); 1878 1879 while (MOud >= 29.5305885) { 1880 MOud -= 29.5305885; 1881 } 1882 1883 for (int 1884 x = 0; x < 15; x++) { 1885 Codemaan[x] = 0; // 15 nullen in codemaan zetten 1886 1887 } 1888 //MOud = 0; 1889 MoonAge = MOud; 1890 MOud *= 2; 1891 MOud *= 1.0158896; 1892 // = 30/29.5305885 1893 MOud = int(MOud); 1894 //Serial.print("MOud: "); 1895 1896 //Serial.println(MOud); 1897 Factor(MOud, false); 1898 v = EH; 1899 w = TT; 1900 1901 1902 //cc = ledcode[w]; 1903 1904 cc = 14 - (w * 2); 1905 if (v < 5) { 1906 Codemaan[cc] 1907 = bindec[v]; 1908 } else { 1909 Codemaan[cc - 1] = bindec[v]; 1910 } 1911} 1912// 1913 ------------------------------------------------ 1914void DagDuur() { 1915 float 1916 BB; 1917 float AZ; 1918 float Decc; 1919 Schrikkeljaar(); 1920 AZ = TotaalDagen(month); 1921 1922 AZ = AZ - Lentepunt + monthDay; 1923 Decc = Declinatie(AZ, Dagen); 1924 ZonOpOnder(Decc, 1925 52.9); // aanroepen routine JaarDagen(); 1926 BB = DagLengte; 1927 1928 Factor(BB 1929 * 100, true); 1930 digitalWrite(dataBitMM, 1); 1931 DDMM(segCode[EH], segCode[TT], 1932 segCode[HT], segCode[DT], segCode2[10]); 1933} 1934//---------------------------------------------------------------- 1935void 1936 SchStand() { 1937 float BB; 1938 float BB2; 1939 float AZ; 1940 Schrikkeljaar(); 1941 1942 AZ = TotaalDagen(month); 1943 //AZ = 345; 1944 AZ = (AZ - Lentepunt) + monthDay; 1945 1946 BB = Declinatie(AZ, Dagen); 1947 BB2 = BB; 1948 1949 BB2 = abs(BB2); // fabs = 1950 absoluut 1951 1952 Factor(BB2 * 100, true); 1953 1954 if (BB >= 0) { 1955 DDMM(segCode[EH], 1956 segCode[TT], segCode[HT], segCode[DT], segCode[16]); 1957 } else { 1958 DDMM(segCode[EH], 1959 segCode[TT], segCode[HT], segCode[DT], segCode[15]); 1960 } 1961} 1962//-------------------------------------------------------------------------- 1963void 1964 LCDAzimuth() { 1965 float BB; 1966 float AZ; 1967 float Decc; 1968 Schrikkeljaar(); 1969 1970 AZ = TotaalDagen(month); 1971 //AZ = 180; 1972 AZ = (AZ - Lentepunt) + monthDay; 1973 1974 Decc = Declinatie(AZ, Dagen); 1975 1976 BB = Hoogte(Decc, 52.9); 1977 1978 Factor(BB 1979 * 100, true); 1980 DDMM(segCode[EH], segCode[TT], segCode[HT], segCode[DT], segCode1[23]); 1981} 1982//------------------------------------------------- 1983float 1984 Tijdvereffening(float dd) { 1985 float Tijd; 1986 float TVV; 1987 Tijd = (7.56 * 1988 SINUS((2 * 180 * (dd - 2.7)) / Dagen)); 1989 Tijd = Tijd + (9.85 * (SINUS((4 * 180 1990 * (10.5 + dd)) / Dagen))); 1991 TVV = (Tijd / 60); 1992 return TVV; 1993} 1994 1995//--------------------------------------------------------- 1996void 1997 Zonsondergang() { 1998 float BB; 1999 float AZ; 2000 float Decc; 2001 float ZZ; 2002 2003 float TVE; 2004 float DM; 2005 Schrikkeljaar(); 2006 AZ = TotaalDagen(month); 2007 2008 AZ = AZ - Lentepunt + monthDay; 2009 Decc = Declinatie(AZ, Dagen); 2010 ZonOpOnder(Decc, 2011 52.9); // aanroepen routine 2012 ZZ = ZonOnder + 0.683333; 2013 ZZ += WT; 2014 AZ 2015 += Lentepunt; 2016 2017 TVE = Tijdvereffening(AZ); 2018 2019 ZZ += TVE; 2020 2021 Factor(ZZ 2022 * 100, true); 2023 DDMM(segCode[EH], segCode[TT], segCode2[1], segCode[HT], segCode[DT]); 2024} 2025//--------------------------------------------------------- 2026void 2027 Zonsopgang() { 2028 float BB; 2029 float AZ; 2030 float Decc; 2031 float ZZ; 2032 2033 float TVE; 2034 float DM; 2035 Schrikkeljaar(); 2036 AZ = TotaalDagen(month); 2037 2038 AZ = AZ - Lentepunt + monthDay; 2039 Decc = Declinatie(AZ, Dagen); 2040 ZonOpOnder(Decc, 2041 52.9); // aanroepen routine 2042 ZZ = ZonOp + 0.683333; 2043 ZZ += WT; 2044 AZ 2045 += Lentepunt; 2046 TVE = Tijdvereffening(AZ); 2047 ZZ += TVE; 2048 2049 Factor(ZZ 2050 * 100, true); 2051 DDMM(segCode[EH], segCode[TT], segCode2[1], segCode[HT], segCode[DT]); 2052} 2053//------------------------------------------------------ 2054void 2055 DagSEC() { 2056 long DS; 2057 long uur; 2058 uur = hour; 2059 DS = (uur * 3600); 2060 2061 DS += (minute * 60); 2062 DS += second; 2063 2064 Factor(DS, false); 2065 DDMM(segCode[EH], 2066 segCode[TT], segCode[HT], segCode[DT], segCode[TDT]); 2067} 2068// -------------------------------------------------------------- 2069void 2070 DagNR() { 2071 long DR; 2072 int AA; 2073 int HB; 2074 int LB; 2075 int HSB; 2076 2077 int LSB; 2078 Schrikkeljaar(); 2079 DR = TotaalDagen(month) + monthDay; 2080 2081 2082 Factor(DR, false); 2083 DDMM(segCode[EH], segCode[TT], segCode[HT], segCode2[1], 2084 segCode2[2]); 2085} 2086// ------------------------------------------------------------------- 2087int 2088 TotaalDagen(int maand) { // dit is een functie 2089 int Dagen; 2090 int dag1 = 2091 maand - 1; 2092 if (Schrikkel == 1) { 2093 Dagen = DagtotaalS[dag1]; 2094 } else 2095 { 2096 Dagen = Dagtotaal[dag1]; 2097 } 2098 return Dagen; 2099} 2100 2101//----------------------------------------------- 2102float 2103 Hoogte(float decl, float brg) { 2104 float HGT; 2105 float HGT2; 2106 HGT = (SINUS(brg) 2107 * SINUS(decl)) + (COSINUS(brg) * COSINUS(decl)); 2108 HGT2 = ARCSINUS(HGT); 2109 2110 return HGT2; 2111} 2112 2113// ------------------------------------------------ 2114void 2115 HzonNU() { 2116 float Tijd1; 2117 float AZ; 2118 float Decc; 2119 float TVE; 2120 2121 float Tijd2; 2122 float HGTE; 2123 float Hoogte; 2124 float ZZ; 2125 Tijd1 = hour 2126 + (minute / 60.0); 2127 Tijd1 = Tijd1 + (second / 3600.0); 2128 Tijd1 = Tijd1 - 2129 WT - 0.683333; 2130 Schrikkeljaar(); 2131 AZ = TotaalDagen(month); 2132 AZ = AZ 2133 - Lentepunt + monthDay; 2134 Decc = Declinatie(AZ, Dagen); 2135 AZ = AZ + Lentepunt; 2136 2137 TVE = Tijdvereffening(AZ); 2138 Tijd1 = Tijd1 - TVE; 2139 Tijd2 = (Tijd1 * 15.0) 2140 - 180.0; 2141 HGTE = (SINUS(52.9) * SINUS(Decc)) + (COSINUS(52.9) * COSINUS(Decc) 2142 * COSINUS(Tijd2)); 2143 Hoogte = ARCSINUS(HGTE); 2144 // Serial.print("hoogte: 2145 "); 2146 //Serial.println(Hoogte); 2147 ZZ = Hoogte; 2148 ZZ = abs(ZZ); // fabs 2149 = absoluut 2150 2151 Factor(ZZ * 100, true); 2152 if (Hoogte >= 0) { 2153 DDMM(segCode[EH], 2154 segCode[TT], segCode[HT], segCode[DT], segCode[16]); 2155 } else { 2156 DDMM(segCode[EH], 2157 segCode[TT], segCode[HT], segCode[DT], segCode[15]); 2158 } 2159} 2160//------------------------------------------------- 2161double 2162 ARCTANGENS(double x) { 2163 double XX; 2164 XX = x; 2165 return atan(XX) * RAD_TO_DEG; 2166} 2167//------------------------------------------------- 2168double 2169 ARCCOSINUS(double x) { 2170 double XX; 2171 XX = x; 2172 return acos(XX) * RAD_TO_DEG; 2173} 2174//------------------------------------------------- 2175double 2176 ARCSINUS(double x) { 2177 double XX; 2178 XX = x; 2179 return asin(XX) * RAD_TO_DEG; 2180} 2181//------------------------------------------------- 2182double 2183 TANGENS(double x) { 2184 double XX; 2185 XX = x * DEG_TO_RAD; 2186 return tan(XX); 2187} 2188//------------------------------------------------- 2189double 2190 COSINUS(double x) { 2191 double XX; 2192 XX = x * DEG_TO_RAD; 2193 return cos(XX); 2194} 2195//------------------------------------------------- 2196double 2197 SINUS(double x) { 2198 double XX; 2199 XX = x * DEG_TO_RAD; 2200 return sin(XX); 2201} 2202// 2203 ----------------------------------------------- 2204double Declinatie(float dag, 2205 float Jaardag) { 2206 double DECL; 2207 DECL = (dag * 360.0 / Jaardag); 2208 DECL 2209 = SINUS(DECL); 2210 return DECL = DECL * 23.5; 2211} 2212//-------------------------------------------------- 2213void 2214 ZonOpOnder(float decl, float brg) { 2215 float ZON; 2216 float ZonOpOn; 2217 float 2218 AA2 = 180.0; 2219 float BB2 = 15.0; 2220 float gr = -1.25; 2221 ZON = (SINUS(gr) 2222 - (SINUS(brg) * (SINUS(decl)))) / (COSINUS(brg) * COSINUS(decl)); 2223 ZonOpOn = 2224 ARCCOSINUS(ZON); 2225 ZonOp = (AA2 - ZonOpOn) / BB2; 2226 ZonOnder = (AA2 + ZonOpOn) 2227 / BB2; 2228 DagLengte = ZonOnder - ZonOp; 2229} 2230 2231//---------------------------------------------------- 2232
Downloadable files
60 led clock analog style
Analog style clock
60 led clock analog style
60 led clock analog style
Analog style clock
60 led clock analog style
Comments
Only logged in users can leave comments