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