Components and supplies
Shift Register- Parallel to Serial
Capacitor 10 pF
Arduino UNO
16 MHz Crystal
5 mm LED: Green
DS3231MPMB1 Peripheral Module
5 mm LED: Red
Resistor 220 ohm
7 Segment LED Display, InfoVue
Apps and platforms
Arduino IDE
Project description
Code
Digital clock
arduino
Binary and normal time
1 2#include <Wire.h> 3#define PI 3.1415926535897932384626 4#define DEG_TO_RAD 0.0174532925199 5#define RAD_TO_DEG 57.295779513082 6 7#include "Button2.h"; // https://github.com/LennartHennigs/Button2 8#include "Rotary.h"; 9#define ROTARY_PIN1 A0 10#define ROTARY_PIN2 A1 11#define BUTTON_PIN A2 12#define CLICKS_PER_STEP 4 // this number depends on your rotary encoder 13#define MIN_POS -100 14#define MAX_POS 100 15#define START_POS 0 16#define INCREMENT 1 // this number is the counter increment on each step 17Button2 bt; 18Rotary rt; 19const byte interruptPin = 2; 20////Pin connected to Serial in of TLC5916 21byte dataPinR = 3; 22 23//Pin connected to Latch of TLC5916 24byte latchPinR = 4; 25 26//Pin connected to ClockPulse of TLC5916 27byte clockPinR = 5; 28 29byte dataPin1 = 6; 30byte latchPin1 = 7; 31byte clockPin1 = 8; 32byte SW1 = 9; 33byte SW2 = 10; 34byte SW3 = 11; 35byte SW4 = 12; 36 37byte LED1[10] = { 38 5, 207, 35, 131, 201, 145, 17, 199, 1, 129 39}; 40 41byte LED2[10] = {// dot is aan 42 4, 206, 34, 130, 200, 144, 16, 198, 0, 128 43}; 44byte LDIG1[10] = { 45 0, 2, 6, 14, 30, 62, 126, 254, 254, 254 46}; 47byte LDIG2[10] = { 48 0, 0, 0, 0, 0, 0, 0, 0, 2, 6 49}; 50byte LDIGdot1[10] = { 51 0, 2, 4, 8, 16, 32, 64, 128, 0, 0 52}; 53byte LDIGdot2[10] = { 54 0, 0, 0, 0, 0, 0, 0, 0, 2, 4 55}; 56byte Schrikkel = 0; 57int Dagtotaal[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; 58int DagtotaalS[12] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; 59byte DagMaand[13] = {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 60byte DagMaandS[13] = {31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 61byte Maan[20] = {2, 13, 24, 5, 16, 27, 8, 19, 30, 11, 22, 3, 14, 25, 6, 17, 29, 10, 21}; 62// epacta getallen 63//eerste getal 2 is het jaar 2017 64//elk jaar verschuift 11, behalve eens in de 19 jaar, dan 12. 65// laatste was in 2014 dan in 2033, en in 2052 66byte AR; 67int second; 68int minute; 69int hour; 70int weekday; 71int monthDay; 72int month; 73int year; 74int Sjaar; 75byte Test; 76byte test1; 77byte test2; 78byte test3; 79byte test4; 80byte a = 0; 81byte b = 0; 82byte c = 0; 83byte d = 0; 84byte e = 0; 85byte f = 0; 86byte g = 0; 87byte h = 0; 88byte i = 0; 89byte j = 0; 90byte k = 0; 91byte m = 0; 92byte WT = 1; 93long HDT; 94long TDT; 95long DT; 96long HT; 97long TT; 98long EH; 99byte ddd[17]; 100int Lentepunt; 101int Dagen; 102float ZonOp; 103float ZonOnder; 104float DagLengte; 105float BG = 52.9; 106float LG = 4.75; 107float BB; 108float BB2; 109float AZ; 110float Decc; 111long DS; 112long uur; 113long DR; 114float ZZ; 115float TVE; 116float DM; 117float Lgt; 118float Tijd1; 119float Tijd2; 120float HGTE; 121int counter = 0; 122volatile int encoderPos = 0; 123boolean buttonPressed = 0; // a flag variable 124volatile byte secondsInterrupt = 0; 125//---------------------------------------------------------------------- 126void setup() { 127 128 //set pins to output because they are addressed in the main loop 129 pinMode(latchPinR, OUTPUT); 130 pinMode(clockPinR, OUTPUT); 131 pinMode(dataPinR, OUTPUT); 132 pinMode(interruptPin, INPUT_PULLUP); 133 pinMode(latchPin1, OUTPUT); 134 pinMode(clockPin1, OUTPUT); 135 pinMode(dataPin1, OUTPUT); 136 pinMode(SW1, INPUT_PULLUP); 137 pinMode(SW2, INPUT_PULLUP); 138 pinMode(SW3, INPUT_PULLUP); 139 pinMode(SW4, INPUT_PULLUP); 140 141 Serial.begin(9600); 142 attachInterrupt(digitalPinToInterrupt(interruptPin), secondsRTC, FALLING); 143 Wire.begin(); // begin I2C routine 144 145 bt.begin(BUTTON_PIN); 146 bt.setPressedHandler(pressed); 147 bt.setReleasedHandler(released); 148 149 rt.begin(ROTARY_PIN1, ROTARY_PIN2, CLICKS_PER_STEP, MIN_POS, MAX_POS, START_POS, INCREMENT); 150 rt.setLeftRotationHandler(showDirection); 151 rt.setRightRotationHandler(showDirection); 152 zet_24uurmode(); 153 SQW1hzOn(); 154 155 TijdDigReset(); 156 Tijdreset (); 157 delay(2000); 158 TijdUitlezen(); 159 Ledtest (); 160 TijdDigTest(); 161 Tijdreset (); 162 delay(2000); 163} 164//------------------------------------------------------------------ 165void secondsRTC(void) { // *** ISR iedere seconde *** 166 secondsInterrupt = 1; // ISR vlag = 1 : er was een 'seconds' interrupt. 167} 168//------------------------------------------------------------------------ 169void TijdUitlezen() { 170 second = lees_seconde(); 171 minute = lees_minuut(); 172 hour = lees_uur(); 173 weekday = lees_dagweek(); //0-6 -> sunday - Saturday 174 monthDay = lees_datum(); 175 month = lees_maand(); 176 year = lees_jaar(); 177 //Serial.println(month); 178 Sjaar = year; 179 Factor(minute, false); 180 c = EH; 181 d = TT; 182 // uur uitlezen/// 183 Factor(hour, false); 184 e = EH; 185 f = TT; 186 // dag uitlezen/// 187 Factor(monthDay, false); 188 g = EH; 189 h = TT; 190 // maand uitlezen/// 191 //Serial.println(month); 192 Factor(month, false); 193 i = EH; 194 j = TT; 195 // jaar uitlezen/// 196 Factor(year, false); 197 k = EH; 198 m = TT; 199 //Serial.println(second); 200} 201//------------------------------------------------------------------------ 202byte AgingRead() { 203 return leesroutine(16);// data is two's complement 204} 205//------------------------------------------------------------------------ 206void zet_24uurmode() {// set 24 hour mode 207 byte uurreg; 208 uurreg = leesroutine(2); 209 if (uurreg > 64){// bit 6 = 64, set to zero 210 uurreg = uurreg - 64; 211 instelroutine(2, uurreg); 212 } 213} 214 215//------------------------------------------------------------------------ 216byte lees_seconde() { // read seconds 217 return BcdToDec(leesroutine(0)); 218} 219//------------------------------------------------------------------------ 220byte lees_minuut() { //read minute 221 return BcdToDec(leesroutine(1)); 222} 223//------------------------------------------------------------------------ 224byte lees_uur() { // read hour 225 return BcdToDec(leesroutine(2)); 226} 227//------------------------------------------------------------------------ 228byte lees_dagweek() { // read DOW 229 return BcdToDec(leesroutine(3)); 230} 231//------------------------------------------------------------------------ 232byte lees_datum() { // read day of month 233 return BcdToDec(leesroutine(4)); 234} 235//------------------------------------------------------------------------ 236byte lees_maand() { // read month 237 return BcdToDec(leesroutine(5)); 238} 239 240//------------------------------------------------------------------------ 241byte lees_jaar() { // read year 242 return BcdToDec(leesroutine(6)); 243} 244//------------------------------------------------------------------------ 245byte BcdToDec(byte val) { 246 return (val / 16 * 10) + (val % 16);// bcd to decimal 247} 248//------------------------------------------------------------------------ 249byte leesroutine(byte adres) {// read register of RTC 250 251 Wire.beginTransmission(0x68); // adress RTC DS1307 or DS3231 252 Wire.write(adres); // address register DS3231 253 Wire.endTransmission(); // einde I2C routine 254 Wire.requestFrom(0x68, 1); 255 return Wire.read(); 256} 257//------------------------------------------------------------------------ 258void instelroutine(byte adres, byte data1) {// set register of RTC 259 Wire.beginTransmission(0x68); // adress RTC DS3231 260 Wire.write(adres); // address register DS3231 261 Wire.write(data1); 262 Wire.endTransmission(); // einde I2C routine 263} 264 265//------------------------------------------------------------------------ 266byte decToBcd(byte val) { 267 return ((val / 10 * 16) + (val % 10)); 268} 269//------------------------------------------------------------------------ 270void Agingadjust(byte data1) {// fine adjust the frequency of the RTC 271 272 instelroutine(16, data1);// data is two's complement 273 /* 274 Positive aging values add capacitance to the array, slowing the 275 oscillator frequency. Negative values remove capacitance from the array, 276 increasing the oscillator frequency. The change in ppm per LSB is different 277 at different temperatures. The frequency vs. temperature curve is shifted by 278 the values used in this registert. At +25C, one LSB typically 279 provides about 0.1ppm change in frequency. 280 */ 281} 282//------------------------------------------------------------------------ 283void SQW1hzOn() {// switch the 1 Hz SQW on 284 instelroutine(14, 0); 285} 286//------------------------------------------------------------------------ 287void zet_jaar(byte data1) { // set year 288 instelroutine(6, decToBcd(data1)); 289} 290//------------------------------------------------------------------------ 291void zet_maand(byte data1) { // set month 292 instelroutine(5, decToBcd(data1)); 293} 294//------------------------------------------------------------------------ 295void zet_datum(byte data1) { // set day of month 296 instelroutine(4, decToBcd(data1)); 297} 298//------------------------------------------------------------------------ 299void zet_dagweekin(byte data1) { // set DOW 300 instelroutine(3, decToBcd(data1)); 301} 302//------------------------------------------------------------------------ 303void zet_uur(byte data1) { // set hour 304 instelroutine(2, decToBcd(data1)); 305} 306//------------------------------------------------------------------------ 307void zet_minuut(byte data1) { // set minute 308 instelroutine(1, decToBcd(data1)); 309} 310//------------------------------------------------------------------------ 311void zet_seconde(byte data1) { // set second 312 instelroutine(0, decToBcd(data1)); 313} 314//--------------------------------------------------------------- 315 316void Schrikkeljaar () { 317 318 Sjaar %= 4; // %= is remainder -------- 319 320 if (Sjaar == 0) 321 { 322 Schrikkel = 1; 323 Lentepunt = 81; 324 Dagen = 366; 325 } 326 else 327 { 328 Schrikkel = 0; 329 Lentepunt = 80; 330 Dagen = 365; 331 } 332//------------------------------------------------- 333} 334void showDirection(Rotary& rt) { 335 //Serial.println(rt.getDirection()); 336 337 counter = rt.getDirection(); 338 if (counter == 255) 339 { 340 counter = -1; 341 } 342 else 343 { 344 counter = 1; 345 } 346 encoderPos += counter; 347 //Serial.println(encoderPos); 348} 349 350 351//-------------------------------------------------------- 352void pressed(Button2& btn) { 353 //Serial.print("pressed "); 354 buttonPressed = 1; 355 //Serial.println(buttonPressed); 356} 357void released(Button2& btn) { 358 // Serial.print("released: "); 359 buttonPressed = 0; 360 //Serial.println(buttonPressed); 361} 362 363 364 365// -------------------------------------------------------------- 366void Factor (long Getal, bool graden) { 367 long Test; 368 //Serial.println(Getal); 369 Test = Getal; 370 HDT = Test / 100000; 371 Test = Test - (HDT * 100000); 372 373 TDT = Test / 10000; 374 Test = Test - (TDT * 10000); 375 376 DT = Test / 1000; 377 Test = Test - (DT * 1000); 378 379 380 HT = Test / 100; 381 Test = Test - (HT * 100); 382 383 if (graden == true) { 384 Test = Test * 0.6; 385 } 386 TT = Test / 10; 387 Test = Test - (TT * 10); 388 389 EH = Test; 390 391} 392 393//--------------------------------------------- 394void readtime() { 395 396 second = lees_seconde();// read seconds 397 // seconde uitlezen/// 398 Factor (second, false); 399 a = EH; 400 b = TT; 401 402 if (second == 0) { 403 minute = lees_minuut();// read minutes 404 // minuut uitlezen/// 405 Factor (minute, false); 406 c = EH; 407 d = TT; 408 } 409 410 if (minute == 0 & second == 0) { 411 hour = lees_uur();// read hour 412 // uur uitlezen/// 413 Factor (hour, false); 414 e = EH; 415 f = TT; 416 } 417 418 if (hour == 0 & second == 0) { 419 weekday = lees_dagweek(); //0-6 -> sunday - Saturday 420 monthDay = lees_datum();// read day of month 421 month = lees_maand();// read month 422 year = lees_jaar();// read year 423 424 // dag uitlezen/// 425 Factor (monthDay , false); 426 g = EH; 427 h = TT; 428 // maand uitlezen/// 429 Factor (month , false); 430 i = EH; 431 j = TT; 432 Factor (year , false); 433 k = EH; 434 m = TT; 435 } 436 437 438} 439//--------------------------------------------------------- 440 441void loop() { 442 443 444 test1 = digitalRead(SW1); 445 test2 = digitalRead(SW2); 446 test3 = digitalRead(SW3); 447 test4 = digitalRead(SW4); 448 Test = test4 * 8; 449 Test += test3 * 4; 450 Test += test2 * 2; 451 Test += test1; 452 453 if (secondsInterrupt == 1) { // **** doe als ISR vlag = 1 **** 454 readtime(); // de subroutine die iedere seconde de tijd registers leest. 455 secondsInterrupt = 0; // zet ISR vlag terug naar '0' 456 dddInstellen(16); 457 } 458 459 switch (Test) { 460 case 0:// 0000 461 if (ddd[0] == 1) 462 { 463 Tijd();//time 464 dddInstellen(0); 465 } 466 TijdDig1();//time digital 467 break; 468 case 1:// 0001 469 if (ddd[1] == 1) 470 { 471 Datum (); 472 dddInstellen(1); 473 } 474 TijdDig1(); 475 break; 476 case 2:// 0010 477 if (ddd[2] == 1) 478 { 479 Tijd(); 480 dddInstellen(2); 481 } 482 TijdDig2(); 483 break; 484 case 3:// 0011 485 if (ddd[3] == 1) 486 { 487 Tijd(); 488 dddInstellen(3); 489 } 490 TijdDig3(); 491 break; 492 case 4:// 0100 493 if (ddd[4] == 1) 494 { 495 if (hour >= 0 & hour < 8) { 496 Tijdreset (); 497 } 498 else 499 { 500 Tijd(); 501 } 502 dddInstellen(4); 503 } 504 break; 505 case 5:// 0101 506 if (ddd[5] == 1) 507 { 508 DagNR(); 509 dddInstellen(5); 510 } 511 TijdDig1(); 512 break; 513 case 6:// 0110 514 if (ddd[6] == 1) 515 { 516 DagSEC(); 517 dddInstellen(6); 518 } 519 TijdDig1(); 520 break; 521 case 7:// 0111 522 if (ddd[7] == 1) 523 { 524 Tijdreset (); 525 dddInstellen(7); 526 } 527 TijdDig1(); 528 break; 529 case 8:// 1000 530 if (ddd[8] == 1) 531 { 532 Tijd(); 533 dddInstellen(8); 534 } 535 TijdDigdot(); 536 break; 537 case 9:// 1001 538 Adjust(); 539 break; 540 case 10:// 1010 541 if (ddd[10] == 1) 542 { 543 Tijdreset (); 544 dddInstellen(10); 545 } 546 TijdDig3(); 547 break; 548 case 11:// 1011 549 if (ddd[11] == 1) 550 { 551 MinutenJaar(); 552 dddInstellen(11); 553 } 554 TijdDig1(); 555 break; 556 case 12:// 1100 557 if (ddd[12] == 1) 558 { 559 Zonsopgang(); 560 dddInstellen(12); 561 } 562 TijdDig1(); 563 break; 564 case 13:// 1101 565 if (ddd[13] == 1) 566 { 567 Zonsondergang(); 568 dddInstellen(13); 569 } 570 TijdDig1(); 571 break; 572 case 14:// 1110 573 if (ddd[14] == 1) 574 { 575 LCDAzimuth(); 576 dddInstellen(14); 577 } 578 TijdDig1(); 579 break; 580 case 15:// 1111 581 if (ddd[15] == 1) 582 { 583 HzonNU(); 584 dddInstellen(15); 585 } 586 TijdDig1(); 587 break; 588 } 589 590 591} 592 593//-------------------------------------------------------------------------------- 594void dddInstellen(byte een) { 595 for (byte x = 0 ; x < 16; x++) 596 { 597 ddd[x] = 1;// alles op 1 zetten 598 } 599 ddd[een] = 0;// 1 van de 16 op 0 zetten, zodat de routine 1 maal doorlopen wordt 600} 601//----------------------------------------------------------- 602void Adjust() { 603 604 rt.loop(); 605 bt.loop(); 606 if (encoderPos < 0) { 607 encoderPos = 0; 608 } 609 if (encoderPos > 7) { 610 encoderPos = 7; 611 } 612 switch (encoderPos) { 613 case 0 : 614 DisplayAdjust(); 615 break; 616 case 1: 617 Displaykeuze1(251); 618 if (encoderPos == 1 && buttonPressed == 1) { 619 encoderPos = 0; 620 AdjustUUR(); 621 } 622 break; 623 case 2: 624 DisplaykeuzeWT(251); 625 if (encoderPos == 2 && buttonPressed == 1) { 626 encoderPos = 0; 627 AdjustWT(); 628 } 629 break; 630 case 3: 631 Displaykeuze2(251); 632 if (encoderPos == 3 && buttonPressed == 1) { 633 encoderPos = 0; 634 AdjustMIN(); 635 } 636 break; 637 638 case 4: 639 Displaykeuze4(251); 640 if (encoderPos == 4 && buttonPressed == 1) { 641 encoderPos = 0; 642 AdjustDAG(); 643 } 644 break; 645 case 5: 646 Displaykeuze5(251); 647 if (encoderPos == 5 && buttonPressed == 1) { 648 encoderPos = 0; 649 AdjustMND(); 650 } 651 break; 652 case 6: 653 Displaykeuze6(251); 654 if (encoderPos == 6 && buttonPressed == 1) { 655 encoderPos = 0; 656 AdjustYR(); 657 } 658 break; 659 case 7: 660 661 AR = AgingRead(); 662 Displaykeuze8(AR); 663 if (encoderPos == 7 && buttonPressed == 1) { 664 encoderPos = 0; 665 AdjustAging(); 666 } 667 break; 668 } 669} 670//------------------------------------------------------------- 671void DDP (int D1, int D2, int D3, int D4, int D5, int D6) { 672 673 digitalWrite(latchPin1, LOW); 674 shiftOut(dataPin1, clockPin1, MSBFIRST, D1); 675 shiftOut(dataPin1, clockPin1, MSBFIRST, D2); 676 shiftOut(dataPin1, clockPin1, MSBFIRST, D3); 677 shiftOut(dataPin1, clockPin1, MSBFIRST, D4); 678 shiftOut(dataPin1, clockPin1, MSBFIRST, D5); 679 shiftOut(dataPin1, clockPin1, MSBFIRST, D6); 680 digitalWrite(latchPin1, HIGH); 681 682} 683//------------------------------------------------------------- 684void DisplayAdjust() { 685 DDP(57, 145, 13, 15, 11, 65); 686} 687 688//------------------------------------------------------------- 689void AdjustUUR() { 690 int exx = 0; 691 Displaykeuze1(179); 692 encoderPos = 0; 693 buttonPressed = 0; 694 delay(1000); 695 while (exx == 0) { 696 697 698 //Serial.println (encoderPos); 699 if (encoderPos == 0) { 700 Displaykeuze1(251);// uur 701 } 702 //----------------- 703 rt.loop(); 704 bt.loop(); 705 706 if ( encoderPos > 1) { 707 hour = hour + 1; 708 if (hour == 24) { 709 hour = 0; 710 } 711 Factor (hour, false); 712 e = EH; 713 f = TT; 714 Displaykeuze1(247);// uur 715 encoderPos = 1; 716 717 } 718 719 // -------------------------- 720 if ( encoderPos < -1) { 721 hour = hour - 1; 722 if (hour < 0) { 723 hour = 23; 724 } 725 Factor (hour, false); 726 e = EH; 727 f = TT; 728 Displaykeuze1(191);// uur 729 encoderPos = -1; 730 731 } 732 if (buttonPressed == 1 & encoderPos != 0) { 733 zet_uur(hour);// set hour 734 Displaykeuze1(183);// uur 735 encoderPos = 0; 736 exx = 1; 737 } 738 } 739} 740// ------------------------------------------------------ 741void Displaykeuze1(int x) { 742 DDP(LED1[e], LED1[f], x, 123, 31, 31); 743} 744//------------------------------------------------------------- 745void AdjustWT() { 746 747 int exx = 0; 748 //int Zt ; 749 //Zt = WT; 750 DisplaykeuzeWT(179); 751 delay(1000); 752 while (exx == 0) { 753 754 755 //Serial.println (encoderPos); 756 if (encoderPos == 0) { 757 DisplaykeuzeWT(251); 758 } 759 //----------------- 760 rt.loop(); 761 bt.loop(); 762 763 if ( encoderPos > 1) { 764 WT = 1; 765 DisplaykeuzeWT(247); 766 encoderPos = 1; 767 768 } 769 770 // -------------------------- 771 if ( encoderPos < -1) { 772 773 WT = 0; 774 DisplaykeuzeWT(191); 775 encoderPos = -1; 776 777 } 778 if (buttonPressed == 1 & encoderPos != 0) { 779 DisplaykeuzeWT(183); 780 WT = 0; 781 782 encoderPos = 0; 783 exx = 1; 784 } 785 } 786} 787 788 789// ------------------------------------------------------ 790void DisplaykeuzeWT(int x) { 791 DDP(LED1[WT], 255, x, 255, 57, 57); 792} 793//----------------------------------------------------------- 794void AdjustMIN() { 795 int exx = 0; 796 797 Displaykeuze2(179); 798 encoderPos = 0; 799 buttonPressed = 0; 800 delay(1000); 801 802 while (exx == 0) { 803 804 805 806 //Serial.println (encoderPos); 807 if (encoderPos == 0) { 808 Displaykeuze2(251);// min 809 } 810 //----------------- 811 rt.loop(); 812 bt.loop(); 813 814 if ( encoderPos > 1) { 815 minute = minute + 1; 816 if (minute == 60) { 817 minute = 0; 818 } 819 Factor (minute, false); 820 c = EH; 821 d = TT; 822 Displaykeuze2(247);// min 823 encoderPos = 1; 824 } 825 826 // -------------------------- 827 if ( encoderPos < -1) { 828 minute = minute - 1; 829 if (minute < 0) { 830 minute = 59; 831 } 832 Factor (minute, false); 833 c = EH; 834 d = TT; 835 Displaykeuze2(191);// uur 836 encoderPos = -1; 837 } 838 if (buttonPressed == 1 & encoderPos != 0) { 839 zet_seconde(0); 840 zet_minuut(minute); 841 Displaykeuze2(183);// min 842 843 encoderPos = 0; 844 exx = 1; 845 } 846 847 } 848} 849 850// ------------------------------------------------------ 851void Displaykeuze2(int x) { 852 DDP(LED1[c], LED1[d], x, 91, 207, 69); 853} 854//---------------------------------------------------------- 855void AdjustDAG() { 856 int exx = 0; 857 858 Displaykeuze4(179); 859 encoderPos = 0; 860 buttonPressed = 0; 861 delay(1000); 862 863 while (exx == 0) { 864 865 866 867 868 if (encoderPos == 0) { 869 Displaykeuze4(251);// min 870 } 871 //----------------- 872 rt.loop(); 873 bt.loop(); 874 875 if ( encoderPos > 1) { 876 monthDay = monthDay + 1; 877 if (monthDay == 32) { 878 monthDay = 1; 879 } 880 Factor (monthDay , false); 881 g = EH; 882 h = TT; 883 Displaykeuze4(247);// min 884 encoderPos = 1; 885 } 886 887 // -------------------------- 888 if ( encoderPos < -1) { 889 monthDay = monthDay - 1; 890 if (monthDay == 0) { 891 monthDay = 31; 892 } 893 Factor (monthDay , false); 894 g = EH; 895 h = TT; 896 Displaykeuze4(191);// uur 897 898 encoderPos = -1; 899 } 900 if (buttonPressed == 1 & encoderPos != 0) { 901 zet_datum(monthDay); 902 Displaykeuze4(183);// min 903 904 encoderPos = 0; 905 exx = 1; 906 } 907 908 } 909} 910// ------------------------------------------------------ 911void Displaykeuze4(int x) { 912 DDP(LED1[g], LED1[h], x, 137, 65, 11); 913} 914//------------------------------------------------------- 915void AdjustMND() { 916 int exx = 0; 917 918 Displaykeuze5(179); 919 encoderPos = 0; 920 buttonPressed = 0; 921 922 923 while (exx == 0) { 924 925 926 927 928 if (encoderPos == 0) { 929 Displaykeuze5(251);// min 930 } 931 //----------------- 932 rt.loop(); 933 bt.loop(); 934 935 if ( encoderPos > 1) { 936 month = month + 1; 937 if (month == 13) { 938 month = 1; 939 } 940 Factor (month , false); 941 i = EH; 942 j = TT; 943 Displaykeuze5(247);// min 944 encoderPos = 1; 945 } 946 947 // -------------------------- 948 if ( encoderPos < -1) { 949 month = month - 1; 950 if (month == 0) { 951 month = 12; 952 } 953 954 Factor (month , false); 955 i = EH; 956 j = TT; 957 Displaykeuze5(191);// uur 958 encoderPos = -1; 959 } 960 if (buttonPressed == 1 & encoderPos != 0) { 961 zet_maand(month);// set month 962 Displaykeuze5(183); 963 964 encoderPos = 0; 965 exx = 1; 966 } 967 968 } 969} 970// ------------------------------------------------------ 971void Displaykeuze5(int x) { 972 DDP(LED1[i], LED1[j], x, 11, 91, 69); 973} 974//------------------------------------------------------ 975void AdjustYR() { 976 int exx = 0; 977 978 979 Displaykeuze6(179); 980 encoderPos = 0; 981 buttonPressed = 0; 982 983 if (year > 2000) { 984 year = year - 2000; 985 } 986 987 while (exx == 0) { 988 989 if (encoderPos == 0) { 990 Displaykeuze6(251);// min 991 } 992 //----------------- 993 rt.loop(); 994 bt.loop(); 995 if ( encoderPos > 1) { 996 year = year + 1; 997 if (year > 99) { 998 year = 0; 999 } 1000 Factor (year , false); 1001 k = EH; 1002 m = TT; 1003 Displaykeuze6(247);// min 1004 1005 encoderPos = 1; 1006 } 1007 1008 // -------------------------- 1009 if ( encoderPos < -1) { 1010 year = year - 1; 1011 if (year < 0) { 1012 year = 99; 1013 } 1014 Factor (year , false); 1015 k = EH; 1016 m = TT; 1017 Displaykeuze6(191);// uur 1018 1019 encoderPos = -1; 1020 } 1021 if (buttonPressed == 1 & encoderPos != 0) { 1022 1023 zet_jaar(year);// set year 1024 Displaykeuze6(183); 1025 1026 encoderPos = 0; 1027 exx = 1; 1028 } 1029 1030 } 1031} 1032// ------------------------------------------------------ 1033void Displaykeuze6(int x) { 1034 DDP(LED1[k], LED1[m], x, 255, 123, 137); 1035} 1036//------------------------------------------------------ 1037void AdjustAging() { 1038 int exx = 0; 1039 encoderPos = 0; 1040 buttonPressed = 0; 1041 1042 Displaykeuze8(AR); 1043 1044 AR = AgingRead(); 1045 1046 while (exx == 0) { 1047 Displaykeuze8(AR); 1048 1049 1050 1051 if (encoderPos == 0) { 1052 Displaykeuze8(AR); 1053 1054 } 1055 //----------------- 1056 rt.loop(); 1057 bt.loop(); 1058 if (encoderPos > 1) { 1059 AR = AR + 1; 1060 if (AR > 127) { 1061 AR = 0; 1062 } 1063 1064 Displaykeuze8(AR); 1065 encoderPos = 1; 1066 } 1067 1068 // -------------------------- 1069 if (encoderPos < -1) { 1070 AR = AR - 1; 1071 if (AR < -128) { 1072 AR = 0; 1073 } 1074 1075 Displaykeuze8(AR); 1076 encoderPos = -1; 1077 } 1078 if (buttonPressed == 1 & encoderPos != 0) { 1079 Agingadjust(AR); 1080 Displaykeuze8(AR); 1081 encoderPos = 0; 1082 buttonPressed = 0; 1083 exx = 1; 1084 } 1085 1086 } 1087} 1088// ------------------------------------------------------ 1089void Displaykeuze8(byte ARR) { 1090 int RR; 1091 // aging register of RTC uses two's complement, a negative number is from 128 to 255 1092 RR = ARR; 1093 1094 if (RR >= 0 & RR < 128) { 1095 Factor(RR, false); 1096 DDP(LED1[EH], LED1[TT], LED1[HT], 255, 255, 65); 1097 } 1098 else 1099 { 1100 RR = RR - 256; 1101 RR = abs(RR); 1102 Factor(RR, false); 1103 DDP(LED1[EH], LED1[TT], LED1[HT], 251, 255, 65); 1104 1105 } 1106 1107} 1108//------------------------------------------------------------- 1109void Tijd() { 1110 DDP(LED1[a], LED1[b], LED1[c], LED1[d], LED2[e], LED1[f]); 1111} 1112//------------------------------------------------------------- 1113void Tijdreset () { 1114 DDP(255, 255, 255, 255, 255, 255); 1115} 1116//------------------------------------------------------------- 1117void DDP2(int D1, int D2, int D3, int D4) { 1118 digitalWrite(latchPinR, LOW); 1119 shiftOut(dataPinR, clockPinR, MSBFIRST, D1);// kolom 1120 shiftOut(dataPinR, clockPinR, MSBFIRST, D2);// rij2 1121 shiftOut(dataPinR, clockPinR, MSBFIRST, D3);//rij1 1122 digitalWrite(latchPinR, HIGH); 1123 delayMicroseconds(D4); 1124} 1125//------------------------------------------------------------- 1126void TijdDig1() { 1127 DDP2(191, LDIG2[a], LDIG1[a], 14); 1128 DDP2(223, 0, LDIG1[b], 14); 1129 DDP2(239, LDIG2[c], LDIG1[c], 14); 1130 DDP2(247, 0, LDIG1[d], 14); 1131 DDP2(251, LDIG2[e], LDIG1[e], 14); 1132 DDP2(253, 0, LDIG1[f], 14); 1133 DDP2(127, 0, 0 , 14); 1134} 1135//------------------------------------------------------------- 1136void TijdDigdot() { 1137 DDP2(191, LDIGdot2[a], LDIGdot1[a], 14 ); 1138 DDP2(223, 0, LDIGdot1[b], 14 ); 1139 DDP2(239, LDIGdot2[c], LDIGdot1[c], 14 ); 1140 DDP2(247, 0, LDIGdot1[d], 14 ); 1141 DDP2(251, LDIGdot2[e], LDIGdot1[e], 14); 1142 DDP2(253, 0, LDIGdot1[f], 14 ); 1143 DDP2(127, 0, 0, 14 ); 1144} 1145//------------------------------------------------------------- 1146void TijdDig2() { 1147 DDP2(191, 0, a * 2, 14 ); // 191 = kolom 6(255-64) seconden eenheid 1148 DDP2(223, 0, b * 2, 14); // 223 = kolom 5 (255-32) seconden tiental 1149 DDP2(239, 0, c * 2, 14); // 239 = kolom 4 (255-16) minuten eenheid 1150 DDP2(247, 0, d * 2, 14); // 247 = kolom 3 minuten tiental 1151 DDP2(251, 0, e * 2, 14); // 251 = kolom 2 uren eenheid 1152 DDP2(253, 0, f * 2, 14); // 253 = kolom 1 uren tiental 1153 DDP2(127, 0, 0 , 14); // extra data zodat laatste led minder fel gaat branden 1154} 1155//------------------------------------------------------------- 1156void TijdDig3() { 1157 DDP2(191, 0, second * 2 , 14); 1158 DDP2(223, 0, 0 , 14); 1159 DDP2(239, 0, minute * 2 , 14); 1160 DDP2(247, 0, 0 , 14); 1161 DDP2(251, 0, hour * 2, 14); 1162 DDP2(253, 0, 0, 14); 1163 DDP2(127, 0, 0, 14); 1164} 1165 1166//------------------------------------------------------------- 1167void TijdDigReset() { 1168 DDP2(191, 0, 0 , 14); // 191 = kolom 6(255-64) seconden eenheid 1169 DDP2(223, 0, 0 , 14); // 223 = kolom 5 (255-32) seconden tiental 1170 DDP2(239, 0, 0 , 14); // 239 = kolom 4 (255-16) minuten eenheid 1171 DDP2(247, 0, 0 , 14); // 247 = kolom 3 minuten tiental 1172 DDP2(251, 0, 0 , 14); // 251 = kolom 2 uren eenheid 1173 DDP2(253, 0, 0 , 14); // 253 = kolom 1 uren tiental 1174 DDP2(127, 0, 0 , 14); // extra data zodat laatste led minder fel gaat branden 1175} 1176//------------------------------------------------------------- 1177void TijdDigTest() { 1178 1179 for (int z = 0; z <= 20; z++) { 1180 for (int x = 0; x <= 10; x++) { 1181 DDP2(191, LDIG2[x], LDIG1[x] , 1000); 1182 DDP2(223, 0, LDIG1[x] , 1000); 1183 DDP2(239, LDIG2[x], LDIG1[x] , 1000); 1184 DDP2(247, 0, LDIG1[x] , 1000); 1185 DDP2(251, LDIG2[x], LDIG1[x] , 1000); 1186 DDP2(253, 0, LDIG1[x] , 1000); 1187 DDP2(127, 0, 0 , 1000); 1188 } 1189 } 1190} 1191//------------------------------------------------------------------ 1192 1193 1194void Datum () { 1195 DDP(LED1[k], LED1[m], LED1[i], LED1[j], LED2[g], LED1[h]); 1196} 1197//--------------------------------------------------------- 1198void Ledtest () { 1199 for (int x = 0; x < 10; x++) { 1200 //Serial.println(x); 1201 DDP(LED1[x], LED1[x], LED1[x], LED1[x], LED2[x], LED1[x]); 1202 delay(400); 1203 } 1204 delay(2000); 1205} 1206 1207// -------------------------------------------------------------- 1208void DagNR() { 1209 Schrikkeljaar (); 1210 DR = TotaalDagen(month) + monthDay; 1211 1212 Factor (DR , false); 1213 DDP(LED1[EH], LED1[TT], LED1[HT], 255, 137, 11); 1214} 1215// ------------------------------------------------------------------- 1216int TotaalDagen(int maand) { // dit is een functie 1217 int Dagen; 1218 int dag1 = maand - 1; 1219 if (Schrikkel == 1) 1220 { 1221 Dagen = DagtotaalS[dag1]; 1222 } 1223 else 1224 { 1225 Dagen = Dagtotaal[dag1]; 1226 } 1227 return Dagen; 1228} 1229//------------------------------------------------------ 1230void DagSEC() { 1231 1232 uur = hour; 1233 DS = (uur * 3600); 1234 DS += (minute * 60); 1235 DS += second; 1236 Factor (DS , false); 1237 DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], LED1[TDT], 255); 1238 1239} 1240//------------------------------------------------------ 1241void MinutenJaar() { 1242 1243 uur = hour; 1244 Schrikkeljaar (); 1245 DS = TotaalDagen(month); 1246 DS += monthDay - 1; 1247 //Serial.println(DS); 1248 DS *= (24 * 60); 1249 DS += (uur * 60); 1250 DS += minute; 1251 Factor (DS , false); 1252 DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], LED1[TDT], LED1[HDT]); 1253 1254} 1255//----------------------------------------------------------------- 1256void LEDMaan() { 1257 float Uur1; 1258 float Min1; 1259 float MOud; 1260 int Index; 1261 float AZ; 1262 float test11; 1263 Schrikkeljaar (); 1264 AZ = TotaalDagen(month); 1265 Min1 = minute; 1266 Uur1 = hour + (Min1 / 60); 1267 AZ = AZ + monthDay ; 1268 AZ = AZ + (Uur1 / 24); 1269 if (year > 2000) { 1270 year = year - 2000; 1271 } 1272 Index = year - 17;// epactagetal ophalen 1273 while (Index > 18) 1274 { 1275 Index = Index - 19; 1276 } 1277 1278 MOud = Maan[Index]; 1279 1280 MOud = MOud + AZ; 1281 1282 while (MOud >= 29.5305885) 1283 { 1284 MOud -= 29.5305885; 1285 } 1286 1287 Factor (MOud * 100 , false); 1288 DDP(91, 11, LED1[EH], LED1[TT], LED1[HT], LED1[DT]); 1289 1290} 1291//--------------------------------------------------------- 1292void Zonsopgang() { 1293 1294 Schrikkeljaar (); 1295 AZ = TotaalDagen(month); 1296 AZ = AZ - Lentepunt + monthDay; 1297 Decc = Declinatie(AZ, Dagen); 1298 ZonOpOnder(Decc, BG);// aanroepen routine 1299 Lgt = LengteGraad(LG); 1300 1301 ZZ = ZonOp + Lgt; 1302 ZZ += WT; 1303 AZ += Lentepunt; 1304 1305 TVE = Tijdvereffening(AZ, Dagen); 1306 1307 ZZ += TVE; 1308 1309 1310 Factor (ZZ * 100 , true); 1311 DDP(97, 31, LED1[EH], LED1[TT], LED1[HT], LED1[DT]); 1312 1313} 1314//--------------------------------------------------------- 1315void Zonsondergang() { 1316 1317 Schrikkeljaar (); 1318 AZ = TotaalDagen(month); 1319 AZ = AZ - Lentepunt + monthDay ; 1320 Decc = Declinatie(AZ, Dagen); 1321 ZonOpOnder(Decc, BG);// aanroepen routine 1322 Lgt = LengteGraad(LG); 1323 ZZ = ZonOnder + Lgt; 1324 ZZ += WT; 1325 AZ += Lentepunt; 1326 1327 TVE = Tijdvereffening(AZ, Dagen); 1328 1329 ZZ += TVE; 1330 1331 Factor (ZZ * 100 , true); 1332 DDP(91, 31, LED1[EH], LED1[TT], LED1[HT], LED1[DT]); 1333 1334} 1335// ----------------------------------------------- 1336 1337double Declinatie(float dag, float Jaardag) { 1338 double DECL; 1339 DECL = (dag * 360.0 / Jaardag); 1340 DECL = SINUS(DECL); 1341 return DECL = DECL * 23.5; 1342} 1343//------------------------------------------------- 1344double ARCTANGENS(double x) { 1345 double XX; 1346 XX = x ; 1347 return atan(XX) * RAD_TO_DEG; 1348} 1349//------------------------------------------------- 1350double ARCCOSINUS(double x) { 1351 double XX; 1352 XX = x ; 1353 return acos(XX) * RAD_TO_DEG; 1354} 1355//------------------------------------------------- 1356double ARCSINUS(double x) { 1357 double XX; 1358 XX = x ; 1359 return asin(XX) * RAD_TO_DEG; 1360} 1361//------------------------------------------------- 1362double TANGENS(double x) { 1363 double XX; 1364 XX = x * DEG_TO_RAD; 1365 return tan(XX); 1366} 1367//------------------------------------------------- 1368double COSINUS(double x) { 1369 double XX; 1370 XX = x * DEG_TO_RAD; 1371 return cos(XX); 1372} 1373//------------------------------------------------- 1374double SINUS(double x) { 1375 double XX; 1376 XX = x * DEG_TO_RAD; 1377 return sin(XX); 1378} 1379 1380//-------------------------------------------------- 1381void ZonOpOnder(float decl, float brg) { 1382 float ZON; 1383 float ZonOpOn; 1384 float AA2 = 180.0; 1385 float BB2 = 15.0; 1386 float gr = -1.25; 1387 ZON = (SINUS(gr) - (SINUS(brg) * (SINUS(decl)))) / (COSINUS(brg) * COSINUS(decl)); 1388 ZonOpOn = ARCCOSINUS(ZON); 1389 ZonOp = (AA2 - ZonOpOn) / BB2; 1390 ZonOnder = (AA2 + ZonOpOn) / BB2; 1391 DagLengte = ZonOnder - ZonOp; 1392 1393} 1394//------------------------------------------------- 1395float Tijdvereffening(float dd, int Dagen) { 1396 float Tijd; 1397 float TVV; 1398 Tijd = (7.56 * SINUS((2 * 180 * (dd - 2.7)) / Dagen)); 1399 Tijd = Tijd + (9.85 * (SINUS((4 * 180 * (10.5 + dd)) / Dagen))); 1400 TVV = (Tijd / 60); 1401 return TVV; 1402} 1403// ------------------------------------------------ 1404void HzonNU() { 1405 float Hoogte; 1406 Tijd1 = hour + (minute / 60.0); 1407 Tijd1 = Tijd1 + (second / 3600.0); 1408 Lgt = LengteGraad(LG); 1409 Tijd1 = Tijd1 - WT - Lgt; 1410 Schrikkeljaar (); 1411 AZ = TotaalDagen(month); 1412 AZ = AZ - Lentepunt + monthDay ; 1413 Decc = Declinatie(AZ, Dagen); 1414 AZ = AZ + Lentepunt; 1415 TVE = Tijdvereffening(AZ, Dagen); 1416 Tijd1 = Tijd1 - TVE; 1417 Tijd2 = (Tijd1 * 15.0) - 180.0; 1418 HGTE = (SINUS(BG) * SINUS(Decc)) + (COSINUS(BG) * COSINUS(Decc) * COSINUS(Tijd2)); 1419 Hoogte = ARCSINUS(HGTE); 1420 // Serial.print("hoogte: "); 1421 //Serial.println(Hoogte); 1422 ZZ = Hoogte; 1423 ZZ = abs(ZZ);// fabs = absoluut 1424 Factor (ZZ * 100 , true); 1425 if (Hoogte >= 0) { 1426 DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], 255, 255); 1427 } 1428 else 1429 { 1430 DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], 251, 255); 1431 } 1432 1433} 1434 1435//---------------------------------------------------------------- 1436void SchStand() { 1437 1438 Schrikkeljaar (); 1439 AZ = TotaalDagen(month); 1440 //AZ = 345; 1441 AZ = (AZ - Lentepunt) + monthDay ; 1442 BB = Declinatie(AZ, Dagen); 1443 BB2 = BB; 1444 BB2 = abs(BB2);// fabs = absoluut 1445 1446 Factor (BB2 * 100 , true); 1447 if (BB >= 0) { 1448 DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], 255, 255); 1449 } 1450 else 1451 { 1452 DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], 255, 251); 1453 } 1454} 1455//----------------------------------------------- 1456float Hoogte(float decl, float brg) { 1457 float HGT; 1458 float HGT2; 1459 HGT = (SINUS(brg) * SINUS(decl)) + (COSINUS(brg) * COSINUS(decl)); 1460 HGT2 = ARCSINUS(HGT); 1461 return HGT2; 1462} 1463//-------------------------------------------------------------------------- 1464void LCDAzimuth() { 1465 1466 Schrikkeljaar (); 1467 AZ = TotaalDagen(month); 1468 //AZ = 180; 1469 AZ = (AZ - Lentepunt) + monthDay ; 1470 Decc = Declinatie(AZ, Dagen); 1471 BB = Hoogte(Decc, BG); 1472 1473 Factor (BB * 100 , true); 1474 DDP(90, 255, LED1[EH], LED1[TT], LED1[HT], LED1[DT]); 1475 1476} 1477//----------------------------------------------------- 1478float LengteGraad(float Lg1) { 1479 float Lgt; 1480 1481 while (Lg1 >= 15) 1482 { 1483 Lg1 -= 15; 1484 } 1485 Lgt = (15 - Lg1); 1486 Lgt = Lgt / 15; 1487 return Lgt; 1488 1489} 1490
Downloadable files
SchematicTdisplayWith39Leds
Digital and normal time
SchematicTdisplayWith39Leds
SchematicTdisplayWith39Leds
Digital and normal time
SchematicTdisplayWith39Leds
Comments
Only logged in users can leave comments
nankie
0 Followers
•0 Projects
Table of contents
Intro
0
0