Components and supplies
Grove - Barometer Sensor (BMP280)
Toggle Switch, Toggle
Rotary Encoder with Push-Button
Shift Register- Parallel to Serial
DS3231MPMB1 Peripheral Module
Resistor 220 ohm
Arduino UNO
Transistor driver UDN2981
Tools and machines
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
astronomical clock
arduino
1// made by Jan G from The Netherlands 2// Astronomical clock using only three shift registers SN74595 3// Date 2022/JUN/01 4// Also using multiplexing 5#include <Wire.h> 6#include <BMx280I2C.h> 7#define I2C_ADDRESS 0x76 8BMx280I2C bmx280(I2C_ADDRESS); 9#define PI 3.141592653 10#define DEG_TO_RAD 0.01745329251 11#define RAD_TO_DEG 57.2957795130 12 13#include "Button2.h"; // https://github.com/LennartHennigs/Button2 14#include "Rotary.h"; 15#define ROTARY_PIN1 A1 16#define ROTARY_PIN2 A2 17#define BUTTON_PIN A0 18#define CLICKS_PER_STEP 4 // this number depends on your rotary encoder 19#define MIN_POS -500 20#define MAX_POS 500 21#define START_POS 0 22#define INCREMENT 1 // this number is the counter increment on each step 23Button2 bt; 24Rotary rt; 25const byte interruptPin = 2; 26 27byte dataPin1 = 5; 28byte latchPin1 = 6; 29byte clockPin1 = 7; 30byte SW1 = 9; 31byte SW2 = 10; 32byte SW3 = 11; 33byte SW4 = 12; 34 35 36/* 37 Showing number 0-9 on a Common Anode 7-segment LED display 38 Displays the numbers 0-9 on the display, 39 A 40 --- 41 F | | B 42 | G | 43 --- 44 E | | C 45 | | 46 --- 47 D 48 display segment : G F E D C B A dp 49 output shiftregister: 7 6 5 4 3 2 1 15 dec inv 50 display number 0 0 1 1 1 1 1 1 0 126 129 51 1 0 0 0 0 1 1 0 0 12 243 52 2 1 0 1 1 0 1 1 0 182 73 53 3 1 0 0 1 1 1 1 0 158 97 54 4 1 1 0 0 1 1 0 0 204 51 55 5 1 1 0 1 1 0 1 0 218 37 56 6 1 1 1 1 1 0 0 0 250 5 57 7 0 0 0 0 1 1 1 0 14 241 58 8 1 1 1 1 1 1 1 0 254 1 59 9 1 1 0 1 1 1 1 0 222 33 60 61 in my project the dot =1, the dot is output 15 of the shiftregister 62 A = 2 , A is output 1 of the shiftregister 63 B = 4 , B is output 2 of the shiftregister 64 C = 8 , C is output 3 of the shiftregister 65 D = 16 , D is output 4 of the shiftregister 66 E = 32 , E is output 5 of the shiftregister 67 F = 64 , F is output 6 of the shiftregister 68 G = 128 , G is output 7 of the shiftregister 69 70 71 number zero = A+B+C+D+E+F = 126 >> invert >> 255-126 = 129 72 number one = B+C = 12 >> invert >> 255-12 = 243 73 number two = A+B+D+E+G = 182 >> invert >> 255-182 = 73 74 number three = A+B+C+D+G = 158 >> invert >> 255-158 = 97 75 etc... for the numbers 4 - 9 76 see Data1[10]{129,243,........ 77 when you have a Common Kathode display, then change the next array to: 78 byte Data1[10] = { 126, 12, 182, 158, 204, 218, 250, 14, 254, 222 }; 79 byte Digit1[10] = { 0, 16, 128, 144, 2, 18, 130, 146, 68, 84 }; 80 byte DisplaySelect1[12] = { 253, 251, 247, 239, 223, 191, 255, 255, 255, 255, 255, 255}; 81 byte DisplaySelect2[12] = { 255, 255, 255, 255, 255, 255, 253, 251, 247, 239, 223, 191}; 82*/ 83byte Data1[10] = { 129, 243, 73, 97, 51, 37, 5, 241, 1, 33 }; 84//---- 85byte Digit1[10] = { 255, 239, 127, 111, 253, 237, 125, 109, 187, 171 }; 86//------ 87byte DisplaySelect1[13] = { 2, 4, 8, 16, 32, 64, 0, 0, 0, 0, 0, 0, 0}; 88 89byte DisplaySelect2[13] = { 0, 0, 0, 0, 0, 0, 2, 4, 8, 16, 32, 64, 0}; 90//----- 91 92byte Schrikkel = 0; 93int Dagtotaal[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; 94int DagtotaalS[12] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }; 95//------------ maan moon ----------------------------------------------------------------- 96byte Maan[20] = { 2, 13, 24, 5, 16, 27, 8, 19, 30, 11, 22, 3, 14, 25, 6, 17, 29, 10, 21 }; 97//---------------- nederlands-------------------------------------------------------- 98// epacta getallen 99//eerste getal van Maan[20] <2> is het jaar 2017, de maan is op 1 januari 2 dagen oud, 100//getal 13 is het jaar 2018, de maan is dan op 1 januari 13 dagen oud, enz.. 101//elk jaar verschuift 11, behalve eens in de 19 jaar, dan 12. 102// laatste was in 2014 dan in 2033, en in 2052 103//----------------------english------------------------------------------- 104//epacta numbers 105// first number of array Maan[20] is 2. This number is the year 2017, the moon age in days is 2 on januari first 106//The next number is 2018, the moon age in days is 13 also on januari first, etc.. 107// every year ads 11, except once in 19 years, then it wil be 12 108// latest was in 2014, then in 2033 etc... 109// moonage = 0 >> new moon, moonage = 14.75 >> full moon 110// moonage = 7.375 >> first quarter, moonage = 22.125 >> last quarter 111// from new moon to the next new moon = 29.5 days 112byte AR; 113int second; 114int minute; 115int hour; 116int weekday; 117int monthDay; 118int month; 119int year; 120int Sjaar; 121byte Test; 122byte test1; 123byte test2; 124byte test3; 125byte test4; 126byte a = 0; 127byte b = 0; 128byte c = 0; 129byte d = 0; 130byte e = 0; 131byte f = 0; 132byte g = 0; 133byte h = 0; 134byte i = 0; 135byte j = 0; 136byte k = 0; 137byte m = 0; 138byte WT = 1; 139double aa = millis(); 140// The variables HDT,TDT,DT,HT,TT and EH are used in the subroutine Factor(); 141long HDT;// hundred thousand ( when number is 123456, HDT = 1) 142long TDT;// ten thousand ( when number is 123456, TDT = 2) 143long DT;//thousand ( when number is 123456, DT = 3) 144long HT;// hundred ( when number is 123456, HT = 4) 145long TT;// tens ( when the number is 123456, TT = 5) 146long EH;// unity (when the number is 123456, EH = 6) 147float temperatuur, pressure, LV; 148int Lentepunt; 149int Dagen; 150float ZZO; 151float ZZN; 152float Stijd1; 153float Maanq; 154float ZonOp; 155float ZonOnder; 156float DagLengte; 157float BG = 52.9;// latitude 158float LG = 4.8;// longitude 159unsigned long currentMillis; 160long interval = 3000; 161long previousMillis = 0; 162volatile int encoderPos = 0; 163volatile byte secondsInterrupt = 0; 164int buttonPressed = 0; 165int counter = 0; 166//---------------------------------------------------------------------- 167void setup() { 168 pinMode(interruptPin, INPUT_PULLUP); 169 pinMode(latchPin1, OUTPUT); 170 pinMode(clockPin1, OUTPUT); 171 pinMode(dataPin1, OUTPUT); 172 pinMode(SW1, INPUT_PULLUP); 173 pinMode(SW2, INPUT_PULLUP); 174 pinMode(SW3, INPUT_PULLUP); 175 pinMode(SW4, INPUT_PULLUP); 176 177 Serial.begin(9600); 178 attachInterrupt(digitalPinToInterrupt(interruptPin), secondsRTC, FALLING); 179 Wire.begin(); // begin I2C routine 180 181 bt.begin(BUTTON_PIN); 182 bt.setPressedHandler(pressed); 183 bt.setReleasedHandler(released); 184 185 rt.begin(ROTARY_PIN1, ROTARY_PIN2, CLICKS_PER_STEP, MIN_POS, MAX_POS, START_POS, INCREMENT); 186 rt.setLeftRotationHandler(showDirection); 187 rt.setRightRotationHandler(showDirection); 188 zet_24uurmode(); 189 190 SQW1hzOn(); 191 // DS3231 seconds, minutes, hours, day of week, date, month, year 192 // first time set of the RTC. remove the '//' in next line to set the time, reinstall it afterwards 193 //setDS3231time(00,58,10,1,29,07,22); 194 bmx280.begin(); 195 bmx280.resetToDefaults(); 196 bmx280.writeOversamplingPressure(BMx280MI::OSRS_P_x16); 197 bmx280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16); 198 delay(2000); 199 TijdUitlezen();// read the time and date variables 200 201 Displaytest1();// display test 202 Displaytest2();// display test 203 Displaytest3();// display test 204 displayuit();// display off 205 delay(2000); 206 // 7 segment display is LTS3401 207 208 209} 210//------------------------------------------------------------------ 211void secondsRTC(void) { // *** ISR iedere seconde *** 212 secondsInterrupt = 1; // ISR vlag = 1 : er was een 'seconds' interrupt. 213} 214 215//------------------------------------------------------------------------ 216byte AgingRead() { 217 return leesroutine(16); 218} 219 220//------------------------------------------------------------------------ 221void zet_24uurmode() {// set 24 hour mode 222 byte uurreg; 223 uurreg = leesroutine(2); 224 //Serial.println(uurreg); 225 if (uurreg > 64) { // bit 6 = 64, set to zero 226 uurreg = uurreg - 64; 227 instelroutine(2, uurreg); 228 } 229} 230 231//------------------------------------------------------------------------ 232byte lees_seconde() { // read seconds 233 return BcdToDec(leesroutine(0)); 234} 235//------------------------------------------------------------------------ 236byte lees_minuut() { //read minute 237 return BcdToDec(leesroutine(1)); 238} 239//------------------------------------------------------------------------ 240byte lees_uur() { // read hour 241 return BcdToDec(leesroutine(2)); 242} 243//------------------------------------------------------------------------ 244byte lees_dagweek() { // read DOW 245 return BcdToDec(leesroutine(3)); 246} 247//------------------------------------------------------------------------ 248byte lees_datum() { // read day of month 249 return BcdToDec(leesroutine(4)); 250} 251//------------------------------------------------------------------------ 252byte lees_maand() { // read month 253 return BcdToDec(leesroutine(5)); 254} 255 256//------------------------------------------------------------------------ 257byte lees_jaar() { // read year 258 return BcdToDec(leesroutine(6)); 259} 260//------------------------------------------------------------------------ 261byte BcdToDec(byte val) { 262 return (val / 16 * 10) + (val % 16);// bcd to decimal 263} 264//------------------------------------------------------------------------ 265byte leesroutine(byte adres) {// read register of RTC 266 267 Wire.beginTransmission(0x68); // adress RTC DS1307 or DS3231 268 Wire.write(adres); // address register DS3231 269 Wire.endTransmission(); // einde I2C routine 270 Wire.requestFrom(0x68, 1); 271 return Wire.read(); 272} 273//------------------------------------------------------------------------ 274void instelroutine(byte adres, byte data1) {// set register of RTC 275 Wire.beginTransmission(0x68); // adress RTC DS3231 276 Wire.write(adres); // address register DS3231 277 Wire.write(data1); 278 Wire.endTransmission(); // einde I2C routine 279} 280//------------------------------------------------------------------------ 281void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, 282 byte month, byte year) 283{ 284 // sets time and date data to DS3231 285 Wire.beginTransmission(0x68); 286 Wire.write(0);// set next input to start at the seconds register 287 Wire.write(decToBcd(second));// set seconds 288 Wire.write(decToBcd(minute));// set minutes 289 Wire.write(decToBcd(hour));// set hours 290 Wire.write(decToBcd(dayOfWeek));// set day of week (1=Sunday, 7=Saturday) 291 Wire.write(decToBcd(dayOfMonth));// set date (1 to 31) 292 Wire.write(decToBcd(month));// set month 293 Wire.write(decToBcd(year));// set year (0 to 99) 294 Wire.endTransmission(); 295} 296//------------------------------------------------------------------------ 297byte decToBcd(byte val) { 298 return ((val / 10 * 16) + (val % 10)); 299} 300//------------------------------------------------------------------------ 301void Agingadjust(byte data1) {// fine adjust the frequency of the RTC 302 303 instelroutine(16, data1); 304 /* 305 Positive aging values add capacitance to the array, slowing the 306 oscillator frequency. Negative values remove capacitance from the array, 307 increasing the oscillator frequency. The change in ppm per LSB is different 308 at different temperatures. The frequency vs. temperature curve is shifted by 309 the values used in this registert. At +25C, one LSB typically 310 provides about 0.1ppm change in frequency. 311 */ 312} 313//------------------------------------------------------------------------ 314void SQW1hzOn() {// switch the 1 Hz SQW on 315 instelroutine(14, 0); 316} 317//------------------------------------------------------------------------ 318void zet_jaar(byte data1) { // set year 319 instelroutine(6, decToBcd(data1)); 320} 321//------------------------------------------------------------------------ 322void zet_maand(byte data1) { // set month 323 instelroutine(5, decToBcd(data1)); 324} 325//------------------------------------------------------------------------ 326void zet_datum(byte data1) { // set day of month 327 instelroutine(4, decToBcd(data1)); 328} 329//------------------------------------------------------------------------ 330void zet_dagweek(byte data1) { // set DOW 331 instelroutine(3, decToBcd(data1)); 332} 333//------------------------------------------------------------------------ 334void zet_uur(byte data1) { // set hour 335 instelroutine(2, decToBcd(data1)); 336} 337//------------------------------------------------------------------------ 338void zet_minuut(byte data1) { // set minute 339 instelroutine(1, decToBcd(data1)); 340} 341//------------------------------------------------------------------------ 342void zet_seconde(byte data1) { // set second 343 instelroutine(0, decToBcd(data1)); 344} 345//------------------------------------------------------------------ 346void TijdUitlezen() { 347 second = lees_seconde(); 348 minute = lees_minuut(); 349 hour = lees_uur(); 350 weekday = lees_dagweek(); //0-6 -> sunday - Saturday 351 monthDay = lees_datum(); 352 month = lees_maand(); 353 year = lees_jaar(); 354 //Serial.println(month); 355 Sjaar = year; 356 Factor(minute, false); 357 c = EH; 358 d = TT; 359 // uur uitlezen/// 360 Factor(hour, false); 361 e = EH; 362 f = TT; 363 // dag uitlezen/// 364 Factor(monthDay, false); 365 g = EH; 366 h = TT; 367 // maand uitlezen/// 368 //Serial.println(month); 369 Factor(month, false); 370 i = EH; 371 j = TT; 372 // jaar uitlezen/// 373 Factor(year, false); 374 k = EH; 375 m = TT; 376 //Serial.println(second); 377} 378 379//--------------------------------------------------------------- 380 381void Schrikkeljaar() {// leapyear 382 383 Sjaar %= 4; // %= is remainder -------- 384 385 if (Sjaar == 0) { 386 Schrikkel = 1; 387 Lentepunt = 81; 388 Dagen = 366; 389 } else { 390 Schrikkel = 0; 391 Lentepunt = 80; 392 Dagen = 365; 393 } 394} 395// -------------------------------------------------------------------- 396 397 398void showDirection(Rotary& rt) { 399 //Serial.println(rt.getDirection()); 400 401 counter = rt.getDirection(); 402 if (counter == 255) 403 { 404 counter = -1; 405 } 406 else 407 { 408 counter = 1; 409 } 410 encoderPos += counter; 411 //Serial.println(encoderPos); 412} 413 414 415//-------------------------------------------------------- 416void pressed(Button2& btn) { 417 //Serial.print("pressed "); 418 buttonPressed = 1; 419 //Serial.println(buttonPressed); 420} 421void released(Button2& btn) { 422 // Serial.print("released: "); 423 buttonPressed = 0; 424 //Serial.println(buttonPressed); 425} 426 427//--------------------------------------------- 428void readtime() { 429 second = lees_seconde();// read seconds 430 // seconde uitlezen/// 431 Factor(second, false); 432 a = EH;// seconds unity ( when seconds is 25, a = 5) 433 b = TT;// seconds tens ( when seconds is 25, b = 2) 434 435 if (second == 0) { 436 minute = lees_minuut();// read minutes 437 // minuut uitlezen/// 438 Factor(minute, false); 439 c = EH;// minutes unity ( when minutes is 25, c = 5) 440 d = TT;// minutes tens ( when minutes is 25, d = 2) 441 } 442 443 if (minute == 0 & second == 0) { 444 hour = lees_uur();// read hour 445 // uur uitlezen/// 446 Factor(hour, false); 447 e = EH;// hour unity ( when hour is 12, e = 2) 448 f = TT;// hour tens ( when hour is 12, f = 1) 449 } 450 451 if (hour == 0 & second == 0) { 452 weekday = lees_dagweek(); //0-6 -> sunday - Saturday 453 monthDay = lees_datum();// read day of month 454 month = lees_maand();// read month 455 year = lees_jaar();// read year 456 457 // dag uitlezen/// 458 Factor(monthDay, false); 459 g = EH;// day unity ( when day is 15, g = 5) 460 h = TT;// day tens ( when day is 15, h = 1) 461 // maand uitlezen/// 462 Factor(month, false); 463 i = EH;// month unity ( when month is 07, i = 7) 464 j = TT;// month tens ( when month is 07, j = 0) 465 Factor(year, false); 466 k = EH;// year unity ( when year is 17, k = 7) 467 m = TT;// year tens ( when year is 17, m = 1) 468 } 469} 470 471 472//--------------------------------------------------------- 473void loop() { 474 475 if (secondsInterrupt == 1) { // **** when ISR vlag = 1 **** 476 readtime(); // subroutine reads every second the time 477 secondsInterrupt = 0; // put ISR flag back to '0' 478 } 479 480 test1 = digitalRead(SW1);// read the switches 481 test2 = digitalRead(SW2); 482 test3 = digitalRead(SW3); 483 test4 = digitalRead(SW4); 484 Test = test4 * 8; 485 Test += test3 * 4; 486 Test += test2 * 2; 487 Test += test1; 488 //Serial.println(Test); 489 490 switch (Test) { 491 case 0: // 0000 492 Tijd();// time and date 493 break; 494 case 1:// 0001 495 Dagnr_LEDMaan();// amount of days since januari first , displa2: the age of the moon in days 496 break; // moonage = 0 >> new moon, moonage = 15 >> full moon 497 case 2:// 0010 498 DagSEC_MinutenJaar();// amount of seconds since 0 hour (max = 86400), displa2: amount of minutes since januari first (max = 527040) 499 break; 500 case 3:// 0011 501 Zon_op_onder();// sun rise and displa2: sun set 502 break;// value depends on latitude and longitude. 503 case 4:// 0100 504 HzonNU();// on display1 the zenith or elevation of the sun at noon, on display2 the actual elevation, it will be zero at sun set or sunrise 505 break; // value depends on latitude 506 case 5:// 0101 507 SchStand(); // display1 tilt of the earth, display2 the time (in hours) between sun rise and sun set 508 break; // tilt = 23.5 start of summer and -23.5 start of winter, and zero start of spring and autumn 509 case 6:// 0110 510 Luchtdruk();// air pressure in mBar, and display2: temperature in celsius 511 break; 512 case 7:// 0111 513 Adjust();// adjust the time and date 514 break; 515 case 8:// 1000 516 Digitaal(); 517 break; 518 case 9:// 1001 Days Of Week, displa2 : weeknumber 519 Dow(); 520 break; 521 case 10:// 1010 522 AzimuthEarth_Moon(); 523 break; 524 case 11:// 1011 525 Equation_MoonAngle(); 526 break; 527 case 12:// 1100 528 SunSetRiseHorizon(); 529 break; 530 case 13:// 1101 531 Lat_Longitude(); 532 break; 533 case 14:// 1110 534 Zuid_MaanPercentage(); 535 break; 536 case 15:// 1111 537 Nachtmode();// night mode: between 0 and 8 the display is blank 538 break; 539 default: 540 Tijd(); 541 break; 542 } 543 //============ every 3 seconds read air pressure sensor =================== 544 currentMillis = millis(); 545 if (currentMillis - previousMillis > interval) { 546 previousMillis = currentMillis; 547 SensorLDuitlezen();// read sensor 548 //Serial.println(pressure); 549 } 550} 551//--------------------------------------------------------- 552void AzimuthEarth_Moon() { // display1 is azimuth earth, display2 is azimuth moon 553 float MaanUur;// position on the horizon 554 float MaanOud;// 0 = north 90 = east 180 = south 270 = west 555 float Stijd0; 556 float LGcorr; 557 float AZ; 558 float TVE; 559 560 LGcorr = LengteGraad(LG); 561 AZ = TotaalDagen(month); 562 AZ = AZ + monthDay; 563 TVE = Tijdvereffening(AZ); 564 565 Stijd0 = timevalue(0); 566 Stijd1 = (Stijd0 * 24) - WT; 567 Stijd1 = Stijd1 - LGcorr - TVE; 568 Stijd1 = Stijd1 * 15; 569 if (Stijd1 < 0) { 570 Stijd1 = 360 + Stijd1; 571 } 572 //Serial.println(Stijd1); 573 574 575 MaanUur = MoonOld(); 576 MaanUur = (MaanUur / 29.5305885) * 360; 577 MaanUur = 360 - MaanUur; 578 Maanq = MaanUur + Stijd1; 579 if (Maanq > 360) { 580 Maanq = Maanq - 360; 581 } 582 if (Maanq < 0) { 583 Maanq = 360 + Maanq; 584 } 585 Factor(Stijd1 * 100, true); 586 display1(199, Data1[TDT], Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 587 588 Factor(Maanq * 100, true); 589 590 display2(87, Data1[TDT], Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 591 592 // when you put - 1 after "]", the display dot will be lit 593} 594//--------------------------------------------------------- 595void Equation_MoonAngle() { // display1: equation of time 596 float AZ;// display2 Angle between earth and moon 597 float TVE;// if angle = 0 it is new moon, if angle = 90, first quarter 598 byte teken;// if angle = 180, it is full moon, if angle = 270, it is last quarter 599 float Hoek; 600 AZ = TotaalDagen(month); 601 AZ = AZ + monthDay; 602 TVE = Tijdvereffening(AZ); 603 604 if (TVE < 0) { 605 TVE = abs(TVE); 606 teken = 127; 607 } 608 else 609 { 610 teken = 255; 611 } 612 TVE = TVE * 60; 613 // Serial.println(TVE,7); 614 615 Factor(TVE * 100, true); 616 display1(15, teken, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 617 618 619 Hoek = Stijd1 - Maanq; 620 if (Hoek < 0) { 621 Hoek = Hoek + 360; 622 } 623 Factor(Hoek * 100, false); 624 display2(19, Data1[TDT], Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 625 626 // when you put - 1 after "]", the display dot will be lit 627} 628//--------------------------------------------------------- 629void SunSetRiseHorizon() { //upper display is sun rise at the moment the sun is 1 degree below the horizon 630 // it will be 90 degrees on start of spring and autumn 631 float AZ;//lower display is sun set at the moment the sun is 1 degree below the horizon 632 // it will be 270 degrees on start of spring and autumn 633 float Decc; 634 float ZZ; 635 float ZZO; 636 float ZZN; 637 float TVE; 638 float Lgt; 639 Schrikkeljaar(); 640 AZ = TotaalDagen(month); 641 AZ = AZ - Lentepunt + monthDay; 642 Decc = Declinatie(AZ, Dagen); 643 ZonOpOnder(Decc, BG); // BG is latitude (51.9) 644 ZZO = ZonOp * 15; 645 ZZN = ZonOnder * 15; 646 647 Factor(ZZO * 100, false); 648 649 display1(199, Data1[TDT], Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 650 651 Factor(ZZN * 100, false); 652 display2(87, Data1[TDT], Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 653 654 // when you put - 1 after "]", the display dot will be lit 655} 656//--------------------------------------------------------- 657void Lat_Longitude() { // upper display is latitude, lower display is longitude 658 659 Factor(BG * 10, false); 660 661 display1(7, 255, Data1[DT], Data1[HT] , Data1[TT] - 1, Data1[EH]); 662 663 Factor(LG * 10, false); 664 display2(143, 255, Data1[DT], Data1[HT] , Data1[TT] - 1, Data1[EH]); 665 666 // when you put - 1 after "]", the display dot will be lit 667} 668//--------------------------------------------------------- 669void Zuid_MaanPercentage() { // upper display is the time when the sun is at south position (and its max elevation) 670 float LGcorr; // lower display is the moon percentage of visible light (0% = new moon, 100% is full moon, 50% is first or last quarter 671 float AZ; 672 float TVE; 673 float Zuiden; 674 float MaanUur; 675 float Mtest; 676 LGcorr = LengteGraad(LG); 677 AZ = TotaalDagen(month); 678 AZ = AZ + monthDay; 679 TVE = Tijdvereffening(AZ); 680 Zuiden = 12 + WT + LGcorr + TVE; 681 682 Factor(Zuiden * 100, true); 683 684 display1(131, 255, Data1[DT], Data1[HT] - 1 , Data1[TT] , Data1[EH]); 685 686 MaanUur = MoonOld(); 687 Mtest = MaanUur; 688 //Serial.println(MaanUur); 689 if (MaanUur > 14.765) { 690 Mtest = (14.765 - (MaanUur - 14.765)); 691 692 } 693 694 MaanUur = (Mtest / 14.765) * 100; 695 Factor(MaanUur * 10, false); 696 display2(91, 255, Data1[DT], Data1[HT] , Data1[TT] - 1 , Data1[EH]); 697 698 // when you put - 1 after "]", the display dot will be lit 699} 700//--------------------------------------------------------- 701void Dow() {// Day of Week 702 int DR; 703 DR = TotaalDagen(month) + monthDay; 704 DR = (DR / 7) + 1; 705 706 Factor(DR, false); 707 display1(67, 71, 131, 255, 255, Data1[weekday]); 708 display2(131, 87, 95, 255, Data1[TT], Data1[EH]); 709} 710//--------------------------------------------------------- 711void Nachtmode() { // night mode: between 0 and 8 the displays are blank 712 if (hour >= 0 & hour < 8) { 713 displayuit();// display off 714 } else { 715 Tijd();// time and date 716 } 717} 718//--------------------------------------------------------- 719void Digitaal() {// semi digital 720 int test; 721 test = a % 2; 722 if (test == 0) { 723 display1(Data1[f], Data1[e] - 1, Data1[d], Data1[c], Data1[b], Data1[a]); 724 display2(Digit1[f], Digit1[e] - 1, Digit1[d], Digit1[c], Digit1[b], Digit1[a]); 725 } 726 else 727 { 728 display1(Data1[f], Data1[e], Data1[d], Data1[c] - 1, Data1[b], Data1[a]); 729 display2(Digit1[f], Digit1[e], Digit1[d], Digit1[c] - 1, Digit1[b], Digit1[a]); 730 } 731} 732// when you put - 1 after "]", the display dot will be lit 733//----------------------------------------------------------- 734void SensorLDuitlezen() {// read sensor 735 bmx280.measure(); 736 while (bmx280.hasValue()) 737 { 738 temperatuur = bmx280.getTemperature(); 739 pressure = bmx280.getPressure(); 740 } 741} 742//----------------------------------------------------------- 743void Luchtdruk() {// air pressure 744 745 //Serial.println(pres); 746 Factor(pressure / 10, false);// air pressure in mBar 747 display1(143, Data1[TDT], Data1[DT], Data1[HT], Data1[TT] - 1, Data1[EH]); 748 749 Factor(temperatuur * 100, false);// temperature in celsius 750 display2(15, 255, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 751} 752// when you put - 1 after "]", the display dot will be lit 753//----------------------------------------------------------- 754void Adjust() { 755 rt.loop(); 756 bt.loop(); 757 if (encoderPos < 0) { 758 encoderPos = 0; 759 760 } 761 //Serial.println(encoderPos); 762 if (encoderPos > 10) { 763 encoderPos = 10; 764 } 765 switch (encoderPos) { 766 767 case 0: 768 DisplayAdjust(); 769 break; 770 case 1: 771 DisplayAdjust(); 772 Displaykeuze1(127); 773 774 if (encoderPos == 1 && buttonPressed == 1) { 775 encoderPos = 0; 776 777 buttonPressed = 0; 778 AdjustUUR(); 779 } 780 break; 781 case 2: 782 DisplayAdjust(); 783 DisplaykeuzeWT(127); 784 if (encoderPos == 2 && buttonPressed == 1) { 785 encoderPos = 0; 786 787 buttonPressed = 0; 788 AdjustWT(); 789 } 790 break; 791 case 3: 792 DisplayAdjust(); 793 Displaykeuze2(127); 794 if (encoderPos == 3 && buttonPressed == 1) { 795 encoderPos = 0; 796 797 buttonPressed = 0; 798 AdjustMIN(); 799 } 800 break; 801 case 4: 802 DisplayAdjust(); 803 Displaykeuze3(127); 804 if (encoderPos == 4 && buttonPressed == 1) { 805 encoderPos = 0; 806 807 buttonPressed = 0; 808 AdjustDAG(); 809 } 810 break; 811 case 5: 812 DisplayAdjust(); 813 Displaykeuze5(127); 814 if (encoderPos == 5 && buttonPressed == 1) { 815 encoderPos = 0; 816 817 buttonPressed = 0; 818 AdjustMND(); 819 } 820 break; 821 case 6: 822 DisplayAdjust(); 823 Displaykeuze6(127); 824 if (encoderPos == 6 && buttonPressed == 1) { 825 encoderPos = 0; 826 827 buttonPressed = 0; 828 AdjustYR(); 829 } 830 break; 831 case 7: 832 DisplayAdjust(); 833 Displaykeuze7(127); 834 if (encoderPos == 7 && buttonPressed == 1) { 835 encoderPos = 0; 836 837 buttonPressed = 0; 838 AdjustDOW(); 839 } 840 break; 841 case 8: 842 DisplayAdjust(); 843 AR = AgingRead(); 844 Displaykeuze8(AR); 845 if (encoderPos == 8 && buttonPressed == 1) { 846 encoderPos = 0; 847 848 buttonPressed = 0; 849 AdjustAging(); 850 } 851 break; 852 case 9: 853 DisplayAdjust(); 854 Displaykeuze9(BG, 7); 855 if (encoderPos == 9 && buttonPressed == 1) { 856 encoderPos = 0; 857 buttonPressed = 0; 858 Adjustlatitude(); 859 } 860 break; 861 case 10: 862 DisplayAdjust(); 863 Displaykeuze9(LG, 143); 864 if (encoderPos == 10 && buttonPressed == 1) { 865 encoderPos = 0; 866 buttonPressed = 0; 867 Adjustlongitude(); 868 } 869 break; 870 } 871} 872//------------------------------------------------------------- 873void DisplayAdjust() { 874 display1(17, 67, 195, 131, 37, 15); 875} 876 877//------------------------------------------------------------- 878void AdjustUUR() {// adjust hour 879 int exx = 0; 880 int cc; 881 delay(100); 882 cc = 109; 883 Displaykeuze1(cc); 884 encoderPos = 0; 885 buttonPressed = 0; 886 887 while (exx == 0) { 888 rt.loop(); 889 bt.loop(); 890 //Serial.println(cc); 891 892 Displaykeuze1(cc); 893 if (encoderPos == 0) { 894 Factor(hour, false); 895 e = EH; 896 f = TT; 897 cc = 127; 898 Displaykeuze1(cc); 899 900 } 901 //----------------- 902 903 if (encoderPos > 1) { 904 hour = hour + 1; 905 if (hour == 24) { 906 hour = 0; 907 } 908 Factor(hour, false); 909 e = EH; 910 f = TT; 911 cc = 253; 912 913 914 //Serial.println(cc); 915 916 917 encoderPos = 1; 918 } 919 // -------------------------- 920 if (encoderPos < -1) { 921 hour = hour - 1; 922 if (hour < 0) { 923 hour = 23; 924 } 925 Factor(hour, false); 926 e = EH; 927 f = TT; 928 cc = 239; 929 930 931 encoderPos = -1; 932 } 933 934 if (buttonPressed == 1 & encoderPos != 0) { 935 zet_uur(hour); 936 cc = 237; 937 Displaykeuze1(cc); 938 buttonPressed = 0; 939 encoderPos = 0; 940 exx = 1; 941 } 942 943 } 944 945} 946 947// ------------------------------------------------------ 948void Displaykeuze1(int x) { 949 display2(199, 199, 95, x, Data1[f], Data1[e]); 950} 951//------------------------------------------------------------- 952void AdjustWT() {// timesaving >> 0 = wintertime, 1 = summertime 953 int cc; 954 int exx = 0; 955 DisplaykeuzeWT(109); 956 encoderPos = 0; 957 buttonPressed = 0; 958 while (exx == 0) { 959 rt.loop(); 960 bt.loop(); 961 962 DisplaykeuzeWT(cc); 963 //Serial.println (memC); 964 if (encoderPos == 0) { 965 DisplaykeuzeWT(127); 966 cc = 127; 967 } 968 //----------------- 969 970 971 if (encoderPos > 1) { 972 WT = 1; 973 DisplaykeuzeWT(253); 974 cc = 253; 975 encoderPos = 1; 976 } 977 978 // -------------------------- 979 if (encoderPos < -1) { 980 WT = 0; 981 DisplaykeuzeWT(239); 982 cc = 239; 983 encoderPos = -1; 984 } 985 if (buttonPressed == 1 & encoderPos != 0) { 986 DisplaykeuzeWT(109); 987 cc = 109; 988 encoderPos = 0; 989 buttonPressed = 0; 990 exx = 1; 991 } 992 993 } 994} 995 996 997// ------------------------------------------------------ 998void DisplaykeuzeWT(int x) { 999 display2(15, 15, 255, x, 255, Data1[WT]); 1000} 1001//----------------------------------------------------------- 1002void AdjustMIN() {// adjust minute 1003 int exx = 0; 1004 int cc; 1005 encoderPos = 0; 1006 1007 Displaykeuze2(109); 1008 1009 1010 while (exx == 0) { 1011 Displaykeuze2(cc); 1012 rt.loop(); 1013 bt.loop(); 1014 1015 1016 if (encoderPos == 0) { 1017 Displaykeuze2(127); 1018 cc = 127; 1019 } 1020 //----------------- 1021 1022 1023 1024 if (encoderPos > 1) { 1025 minute = minute + 1; 1026 if (minute == 60) { 1027 minute = 0; 1028 } 1029 Factor(minute, false); 1030 c = EH; 1031 d = TT; 1032 Displaykeuze2(253); 1033 cc = 253; 1034 encoderPos = 1; 1035 } 1036 1037 // -------------------------- 1038 if (encoderPos < -1) { 1039 minute = minute - 1; 1040 if (minute < 0) { 1041 minute = 59; 1042 } 1043 Factor(minute, false); 1044 c = EH; 1045 d = TT; 1046 Displaykeuze2(239); 1047 cc = 239; 1048 encoderPos = -1; 1049 } 1050 if (buttonPressed == 1 & encoderPos != 0) { 1051 zet_seconde(0); 1052 zet_minuut(minute); 1053 1054 Displaykeuze2(109); 1055 cc = 109; 1056 encoderPos = 0; 1057 1058 exx = 1; 1059 } 1060 1061 } 1062} 1063 1064// ------------------------------------------------------ 1065void Displaykeuze2(int x) { 1066 display2(145, 243, 87, x, Data1[d], Data1[c]); 1067} 1068 1069//---------------------------------------------------------- 1070void AdjustDAG() {// adjust day 1071 int exx = 0; 1072 int cc; 1073 encoderPos = 0; 1074 1075 Displaykeuze3(109); 1076 1077 1078 while (exx == 0) { 1079 Displaykeuze3(cc); 1080 rt.loop(); 1081 bt.loop(); 1082 1083 1084 if (encoderPos == 0) { 1085 Displaykeuze3(127); 1086 cc = 127; 1087 } 1088 //----------------- 1089 1090 1091 1092 if (encoderPos > 1) { 1093 monthDay = monthDay + 1; 1094 if (monthDay == 32) { 1095 monthDay = 1; 1096 } 1097 Factor(monthDay, false); 1098 g = EH; 1099 h = TT; 1100 Displaykeuze3(253); 1101 cc = 253; 1102 encoderPos = 1; 1103 } 1104 1105 // -------------------------- 1106 if (encoderPos < -1) { 1107 monthDay = monthDay - 1; 1108 if (monthDay == 0) { 1109 monthDay = 31; 1110 } 1111 Factor(monthDay, false); 1112 g = EH; 1113 h = TT; 1114 Displaykeuze3(239); 1115 cc = 239; 1116 encoderPos = -1; 1117 } 1118 if (buttonPressed == 1 & encoderPos != 0) { 1119 zet_datum(monthDay); 1120 Displaykeuze3(109); 1121 cc = 109; 1122 encoderPos = 0; 1123 1124 exx = 1; 1125 } 1126 1127 } 1128} 1129// ------------------------------------------------------ 1130void Displaykeuze3(int x) { 1131 display2(67, 17, 35, x, Data1[h], Data1[g]); 1132} 1133//------------------------------------------------------- 1134void AdjustMND() {// Adjust month 1135 int exx = 0; 1136 int cc; 1137 1138 encoderPos = 0; 1139 1140 Displaykeuze5(109); 1141 1142 1143 while (exx == 0) { 1144 Displaykeuze5(cc); 1145 rt.loop(); 1146 bt.loop(); 1147 1148 1149 if (encoderPos == 0) { 1150 Displaykeuze5(127); 1151 cc = 127; 1152 } 1153 //----------------- 1154 1155 1156 1157 if (encoderPos > 1) { 1158 month = month + 1; 1159 if (month == 13) { 1160 month = 1; 1161 } 1162 Factor(month, false); 1163 i = EH; 1164 j = TT; 1165 Displaykeuze5(253); 1166 cc = 253; 1167 encoderPos = 1; 1168 } 1169 1170 // -------------------------- 1171 if (encoderPos < -1) { 1172 month = month - 1; 1173 if (month == 0) { 1174 month = 12; 1175 } 1176 1177 Factor(month, false); 1178 i = EH; 1179 j = TT; 1180 Displaykeuze5(239); 1181 cc = 239; 1182 encoderPos = -1; 1183 } 1184 if (buttonPressed == 1 & encoderPos != 0) { 1185 zet_maand(month); 1186 Displaykeuze5(109); 1187 cc = 109; 1188 encoderPos = 0; 1189 1190 exx = 1; 1191 } 1192 1193 } 1194} 1195// ------------------------------------------------------ 1196void Displaykeuze5(int x) { 1197 display2(145, 87, 67, x, Data1[j], Data1[i]); 1198} 1199//------------------------------------------------------ 1200void AdjustYR() {// Adjust year 1201 int exx = 0; 1202 int cc; 1203 encoderPos = 0; 1204 1205 1206 Displaykeuze6(109); 1207 1208 if (year > 2000) { 1209 year = year - 2000; 1210 } 1211 1212 while (exx == 0) { 1213 Displaykeuze6(cc); 1214 rt.loop(); 1215 bt.loop(); 1216 1217 1218 if (encoderPos == 0) { 1219 Displaykeuze6(127); 1220 cc = 127; 1221 } 1222 //----------------- 1223 1224 1225 if (encoderPos > 1) { 1226 year = year + 1; 1227 if (year > 99) { 1228 year = 0; 1229 } 1230 Factor(year, false); 1231 k = EH; 1232 m = TT; 1233 Displaykeuze6(253); 1234 cc = 253; 1235 encoderPos = 1; 1236 } 1237 1238 // -------------------------- 1239 if (encoderPos < -1) { 1240 year = year - 1; 1241 if (year < 0) { 1242 year = 99; 1243 } 1244 Factor(year, false); 1245 k = EH; 1246 m = TT; 1247 Displaykeuze6(239); 1248 cc = 239; 1249 encoderPos = -1; 1250 } 1251 if (buttonPressed == 1 & encoderPos != 0) { 1252 zet_jaar(year); 1253 Displaykeuze6(109); 1254 cc = 109; 1255 encoderPos = 0; 1256 1257 exx = 1; 1258 } 1259 } 1260} 1261// ------------------------------------------------------ 1262void Displaykeuze6(int x) { 1263 display2(35, 95, 255, x, Data1[m], Data1[k]); 1264} 1265 1266//------------------------------------------------------ 1267void AdjustDOW() {// Day Of Week 1268 int exx = 0; 1269 int cc; 1270 encoderPos = 0; 1271 1272 1273 Displaykeuze7(109); 1274 1275 1276 1277 while (exx == 0) { 1278 Displaykeuze7(cc); 1279 rt.loop(); 1280 bt.loop(); 1281 1282 1283 if (encoderPos == 0) { 1284 Displaykeuze7(127); 1285 cc = 127; 1286 } 1287 //----------------- 1288 1289 1290 if (encoderPos > 1) { 1291 weekday = weekday + 1; 1292 if (weekday > 7) { 1293 weekday = 1; 1294 } 1295 1296 Displaykeuze7(253); 1297 cc = 253; 1298 encoderPos = 1; 1299 } 1300 1301 // -------------------------- 1302 if (encoderPos < -1) { 1303 weekday = weekday - 1; 1304 if (weekday < 1) { 1305 weekday = 7; 1306 } 1307 1308 Displaykeuze7(239); 1309 cc = 239; 1310 encoderPos = -1; 1311 } 1312 if (buttonPressed == 1 & encoderPos != 0) { 1313 zet_dagweek(weekday); 1314 Displaykeuze7(109); 1315 cc = 109; 1316 encoderPos = 0; 1317 1318 exx = 1; 1319 } 1320 } 1321} 1322// ------------------------------------------------------ 1323void Displaykeuze7(int x) { 1324 display2(67, 71, 131, 255, x, Data1[weekday]); 1325} 1326//------------------------------------------------------ 1327void AdjustAging() {// routine to fine adjust the RTC 1328 int exx = 0; 1329 encoderPos = 0; 1330 1331 1332 Displaykeuze8(AR); 1333 1334 AR = AgingRead(); 1335 1336 while (exx == 0) { 1337 Displaykeuze8(AR); 1338 rt.loop(); 1339 bt.loop(); 1340 1341 1342 if (encoderPos == 0) { 1343 Displaykeuze8(AR); 1344 1345 } 1346 //----------------- 1347 1348 1349 if (encoderPos > 1) { 1350 AR = AR + 1; 1351 if (AR > 127) { 1352 AR = 0; 1353 } 1354 1355 Displaykeuze8(AR); 1356 encoderPos = 1; 1357 } 1358 1359 // -------------------------- 1360 if (encoderPos < -1) { 1361 AR = AR - 1; 1362 if (AR < -128) { 1363 AR = 0; 1364 } 1365 1366 Displaykeuze8(AR); 1367 encoderPos = -1; 1368 } 1369 if (buttonPressed == 1 & encoderPos != 0) { 1370 Agingadjust(AR); 1371 Displaykeuze8(AR); 1372 encoderPos = 0; 1373 1374 exx = 1; 1375 } 1376 1377 } 1378} 1379// ------------------------------------------------------ 1380void Displaykeuze8(byte ARR) { 1381 int RR; 1382 // aging register of RTC uses two's complement, a negative number is from 128 to 255 1383 RR = ARR; 1384 1385 if (RR >= 0 & RR < 128) { 1386 Factor(RR, false); 1387 display2(17, 255, 255, Data1[HT], Data1[TT], Data1[EH]); 1388 } 1389 else 1390 { 1391 RR = RR - 256; 1392 RR = abs(RR); 1393 Factor(RR, false); 1394 display2(17, 255, 127, Data1[HT], Data1[TT], Data1[EH]); 1395 } 1396 1397} 1398//------------------------------------------------------ 1399void Adjustlatitude() { 1400 int exx = 0; 1401 int cc; 1402 encoderPos = 0; 1403 1404 Displaykeuze9(BG, 109); 1405 1406 1407 1408 while (exx == 0) { 1409 Displaykeuze9(BG, cc); 1410 rt.loop(); 1411 bt.loop(); 1412 1413 1414 if (encoderPos == 0) { 1415 Displaykeuze9(BG, 127); 1416 cc = 127; 1417 } 1418 //----------------- 1419 1420 1421 if (encoderPos > 1) { 1422 BG = BG + 0.1; 1423 if (BG > 90) { 1424 BG = 0; 1425 1426 } 1427 1428 Displaykeuze9(BG, 253); 1429 cc = 253; 1430 encoderPos = 1; 1431 } 1432 1433 // -------------------------- 1434 if (encoderPos < -1) { 1435 BG = BG - 0.1; 1436 if (BG < -90) { 1437 BG = 0; 1438 } 1439 1440 Displaykeuze9(BG, 239); 1441 cc = 239; 1442 encoderPos = -1; 1443 } 1444 if (buttonPressed == 1 & encoderPos != 0) { 1445 1446 Displaykeuze9(BG, 109); 1447 cc = 109; 1448 encoderPos = 0; 1449 1450 exx = 1; 1451 } 1452 } 1453} 1454// ------------------------------------------------------ 1455void Displaykeuze9(float x, byte teken) { 1456 if (x < 0) { 1457 x = abs(x); 1458 Factor(x * 10, false); 1459 display2(teken, 255, 127, Data1[HT], Data1[TT] - 1, Data1[EH]); 1460 } 1461 else 1462 { 1463 Factor(x * 10, false); 1464 display2(teken, 255, 255, Data1[HT], Data1[TT] - 1, Data1[EH]); 1465 } 1466} 1467 1468//------------------------------------------------------ 1469void Adjustlongitude() { 1470 int exx = 0; 1471 int cc; 1472 encoderPos = 0; 1473 1474 Displaykeuze9(LG, 109); 1475 1476 1477 1478 while (exx == 0) { 1479 Displaykeuze9(LG, cc); 1480 rt.loop(); 1481 bt.loop(); 1482 1483 1484 if (encoderPos == 0) { 1485 Displaykeuze9(LG, 127); 1486 cc = 127; 1487 } 1488 //----------------- 1489 1490 1491 if (encoderPos > 1) { 1492 LG = LG + 0.1; 1493 if (LG > 180) { 1494 LG = 0; 1495 1496 } 1497 1498 Displaykeuze9(LG, 253); 1499 cc = 253; 1500 encoderPos = 1; 1501 } 1502 1503 // -------------------------- 1504 if (encoderPos < -1) { 1505 LG = LG - 0.1; 1506 if (LG < -180) { 1507 LG = 0; 1508 } 1509 1510 Displaykeuze9(LG, 239); 1511 cc = 239; 1512 encoderPos = -1; 1513 } 1514 if (buttonPressed == 1 & encoderPos != 0) { 1515 1516 Displaykeuze9(LG, 109); 1517 cc = 109; 1518 encoderPos = 0; 1519 1520 exx = 1; 1521 } 1522 } 1523} 1524 1525//------------------------------------------------------------- 1526void Tijd() {// time on display1 and date on display2 1527 int test; 1528 test = a % 2; 1529 if (test == 0) { 1530 display1( Data1[f], Data1[e] - 1, Data1[d], Data1[c], Data1[b], Data1[a]); 1531 } else { 1532 display1( Data1[f], Data1[e], Data1[d], Data1[c] - 1, Data1[b], Data1[a]); 1533 } 1534 display2( Data1[h], Data1[g] - 1, Data1[j], Data1[i] - 1, Data1[m], Data1[k]); 1535 1536 // when you put - 1 after "]", the display dot will be lit 1537} 1538// ------------------------------------------------------------ - 1539void display1(byte D1, byte D2, byte D3, byte D4, byte D5, byte D6) { 1540 DDP(0, D1); 1541 DDP(1, D2); 1542 DDP(2, D3); 1543 DDP(3, D4); 1544 DDP(4, D5); 1545 DDP(5, D6); 1546 DDP(12, 0);// extra line to prevent that the last digit 6 is more bright 1547 DDP(12, 0);// extra line to prevent that the last digit 6 is more bright 1548} 1549// ------------------------------------------------------------ - 1550void display2( byte D1, byte D2, byte D3, byte D4, byte D5, byte D6) { 1551 DDP(6, D1); 1552 DDP(7, D2); 1553 DDP(8, D3); 1554 DDP(9, D4); 1555 DDP(10, D5); 1556 DDP(11, D6); 1557 DDP(12, 0);// extra line to prevent that the last digit 11 is more bright 1558 DDP(12, 0);// extra line to prevent that the last digit 11 is more bright 1559 1560} 1561//------------------------------------------------------------- 1562void DDP(byte DispKeuze, byte DispData) {// the multiplexing routine 1563 1564 digitalWrite(latchPin1, HIGH); 1565 shiftOut(dataPin1, clockPin1, MSBFIRST, DispData); 1566 shiftOut(dataPin1, clockPin1, MSBFIRST, DisplaySelect2[DispKeuze]); 1567 shiftOut(dataPin1, clockPin1, MSBFIRST, DisplaySelect1[DispKeuze]); 1568 digitalWrite(latchPin1, LOW); 1569 //delay(1); 1570} 1571 1572//------------------------------------------------------------------ 1573void displayuit() {// display off 1574 display1(255, 255, 255, 255, 255, 255); 1575 display2(255, 255, 255, 255, 255, 255); 1576} 1577//------------------------------------------------------------------ 1578void Displaytest1() { 1579 for (int x = 0; x < 13; x++) { 1580 Lus(x); 1581 } 1582} 1583//------------------------------------------------------------------ 1584void Displaytest2() { 1585 for (int x = 0; x < 13; x++) { 1586 Lus1(x); 1587 } 1588} 1589//------------------------------------------------------------------ 1590void Displaytest3() { 1591 for (int x = 0; x < 10; x++) { 1592 Lus2(x); 1593 } 1594} 1595//--------------------------------------------------------- 1596void Lus(byte tt) { 1597 int test[13] = { 253, 127, 239, 251, 247, 223, 191, 127, 237, 127, 237, 127, 237 }; 1598 1599 for (int x = 0; x < 40; x++) { 1600 display1(test[tt], test[tt], test[tt], test[tt], test[tt], test[tt]); 1601 display2(test[tt], test[tt], test[tt], test[tt], test[tt], test[tt]); 1602 } 1603} 1604//--------------------------------------------------------- 1605void Lus1(byte tt) { 1606 int test[13] = { 71, 57, 71, 57, 71, 57, 71, 57, 71, 57, 71, 57, 71 }; 1607 1608 for (int x = 0; x < 40; x++) { 1609 display1(test[tt], test[tt], test[tt], test[tt], test[tt], test[tt]); 1610 display2(test[tt], test[tt], test[tt], test[tt], test[tt], test[tt]); 1611 } 1612} 1613//--------------------------------------------------------- 1614void Lus2(byte tt) { 1615 for (int x = 0; x < 40; x++) { 1616 display1(Data1[tt], Data1[tt], Data1[tt], Data1[tt], Data1[tt], Data1[tt]); 1617 display2(Data1[tt], Data1[tt], Data1[tt], Data1[tt], Data1[tt], Data1[tt]); 1618 } 1619} 1620 1621// -------------------------------------------------------------- 1622void Factor(long Getal, bool graden) { 1623 long Test; 1624 //Serial.println(Getal); 1625 Test = Getal; 1626 HDT = Test / 100000; 1627 Test = Test - (HDT * 100000); 1628 1629 TDT = Test / 10000; 1630 Test = Test - (TDT * 10000); 1631 1632 DT = Test / 1000; 1633 Test = Test - (DT * 1000); 1634 1635 1636 HT = Test / 100; 1637 Test = Test - (HT * 100); 1638 1639 if (graden == true) {// when true, the number will be converted into minutes (e.g. 0.9 degrees >> 0 degrees and 54 minutes) 1640 Test = Test * 0.6; 1641 } 1642 TT = Test / 10; 1643 Test = Test - (TT * 10); 1644 1645 EH = Test; 1646} 1647 1648// ------------------------------------------------------------------- 1649int TotaalDagen(int maand) { // dit is een functie 1650 int Dagen; 1651 int dag1 = maand - 1; 1652 if (Schrikkel == 1) { 1653 Dagen = DagtotaalS[dag1]; 1654 } else { 1655 Dagen = Dagtotaal[dag1]; 1656 } 1657 return Dagen; 1658} 1659//------------------------------------------------------ 1660float timevalue(byte TVorSEC) { 1661 float DS; 1662 DS = hour; 1663 switch (TVorSEC) { 1664 case 0://TimeValue in 24 hour format(24 hour = 1) 1665 DS = DS + (minute / 60.0); 1666 DS = DS + (second / 3600.0); 1667 return DS = DS / 24; 1668 break; 1669 case 1://Time in Seconds 1670 DS = DS * 3600; 1671 DS = DS + (minute * 60); 1672 DS = DS + second; 1673 return DS; 1674 break; 1675 } 1676 1677} 1678//------------------------------------------------------ 1679void DagSEC_MinutenJaar() { 1680 float DS; 1681 1682 DS = timevalue(1); 1683 Factor(DS, false);// DS is amount of seconds since midnight 1684 display1(109, Data1[TDT], Data1[DT], Data1[HT], Data1[TT], Data1[EH]); 1685 1686 Schrikkeljaar(); 1687 DS = TotaalDagen(month); 1688 DS += monthDay - 1; 1689 //Serial.println(DS); 1690 DS *= (24 * 60); 1691 DS += (hour * 60); 1692 DS += minute; 1693 1694 Factor(DS, false);// DS is amount of minutes since januari first 1695 display2(Data1[HDT], Data1[TDT], Data1[DT], Data1[HT], Data1[TT], Data1[EH]); 1696} 1697//----------------------------------------------------------------- 1698float MoonOld() { 1699 float Uur1; 1700 float MOud; 1701 int Index; 1702 float AZ; 1703 Schrikkeljaar(); 1704 Uur1 = timevalue(0); 1705 AZ = TotaalDagen(month); 1706 AZ = AZ + monthDay; 1707 AZ = AZ + Uur1; 1708 if (year > 2000) { 1709 year = year - 2000; 1710 } 1711 Index = year - 17; // epactagetal ophalen 1712 while (Index > 18) { 1713 Index = Index - 19; 1714 } 1715 1716 MOud = Maan[Index]; 1717 1718 MOud = MOud + AZ; 1719 1720 while (MOud >= 29.5305885) { 1721 MOud -= 29.5305885; 1722 } 1723 //Serial.println(MOud); 1724 return MOud; 1725} 1726//----------------------------------------------------------------- 1727void Dagnr_LEDMaan() {// moon age in days 1728 float MOud; 1729 int DR; 1730 1731 1732 DR = TotaalDagen(month) + monthDay; 1733 Factor(DR, false);// DR is the amount of days since januari first 1734 display1(67, 87, 255, Data1[HT], Data1[TT], Data1[EH]); 1735 1736 MOud = MoonOld(); 1737 Factor(MOud * 100, false);// MOud is the age of the moon in days. 1738 display2(145, 255, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1739 // when you put - 1 after "]", the display dot will be lit 1740} 1741//--------------------------------------------------------- 1742void Zon_op_onder() {// sun rise, sun set 1743 float AZ; 1744 float Decc; 1745 float ZZ; 1746 float ZZO; 1747 float ZZN; 1748 float TVE; 1749 float Lgt; 1750 Schrikkeljaar(); 1751 AZ = TotaalDagen(month); 1752 AZ = AZ - Lentepunt + monthDay; 1753 Decc = Declinatie(AZ, Dagen); 1754 ZonOpOnder(Decc, BG); // BG is latitude (51.9) 1755 Lgt = LengteGraad(LG); // LG is longitude (4.75) 1756 1757 AZ += Lentepunt; 1758 TVE = Tijdvereffening(AZ); 1759 ZZ = WT; 1760 ZZ += TVE; 1761 ZZO = ZZ + ZonOp + Lgt; 1762 ZZN = ZZ + ZonOnder + Lgt; 1763 Factor(ZZO * 100, true); //ZZO is sunrise 1764 1765 display1(25, 255, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1766 1767 Factor(ZZN * 100, true);//ZZN is sunset 1768 display2(87, 255, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1769} 1770// when you put - 1 after "]", the display dot will be lit 1771// ----------------------------------------------- 1772 1773double Declinatie(float dag, float Jaardag) {// tilt of the earth 1774 double DECL; 1775 DECL = (dag * 360.0 / Jaardag); 1776 DECL = SINUS(DECL); 1777 return DECL = DECL * 23.5; 1778} 1779//------------------------------------------------- 1780double ARCTANGENS(double x) { 1781 double XX; 1782 XX = x; 1783 return atan(XX) * RAD_TO_DEG; 1784} 1785//------------------------------------------------- 1786double ARCCOSINUS(double x) { 1787 double XX; 1788 XX = x; 1789 return acos(XX) * RAD_TO_DEG; 1790} 1791//------------------------------------------------- 1792double ARCSINUS(double x) { 1793 double XX; 1794 XX = x; 1795 return asin(XX) * RAD_TO_DEG; 1796} 1797//------------------------------------------------- 1798double TANGENS(double x) { 1799 double XX; 1800 XX = x * DEG_TO_RAD; 1801 return tan(XX); 1802} 1803//------------------------------------------------- 1804double COSINUS(double x) { 1805 double XX; 1806 XX = x * DEG_TO_RAD; 1807 return cos(XX); 1808} 1809//------------------------------------------------- 1810double SINUS(double x) { 1811 double XX; 1812 XX = x * DEG_TO_RAD; 1813 return sin(XX); 1814} 1815 1816//-------------------------------------------------- 1817void ZonOpOnder(float decl, float brg) {// sun rise, sun set 1818 float ZON; 1819 float ZonOpOn; 1820 float AA2 = 180.0; 1821 float BB2 = 15.0; 1822 float gr = -1.25;// when the sun is -1.25 degree below horizon, it is the time of sun rise/sun set 1823 ZON = (SINUS(gr) - (SINUS(brg) * (SINUS(decl)))) / (COSINUS(brg) * COSINUS(decl)); 1824 ZonOpOn = ARCCOSINUS(ZON); 1825 ZonOp = (AA2 - ZonOpOn) / BB2; 1826 ZonOnder = (AA2 + ZonOpOn) / BB2; 1827 DagLengte = ZonOnder - ZonOp; 1828} 1829//------------------------------------------------- 1830float Tijdvereffening(float dd) {// Equation of time 1831 float Tijd;// dd = dagen sinds 1 januari 1832 float TVV; 1833 Schrikkeljaar();// Dagen = 365 of 366 1834 Tijd = (7.56 * SINUS((2 * 180 * (dd - 2.7)) / Dagen)); 1835 Tijd = Tijd + (9.85 * (SINUS((4 * 180 * (10.5 + dd)) / Dagen))); 1836 TVV = (Tijd / 60);// tijd in uren 1837 return TVV; 1838} 1839// ------------------------------------------------ 1840void HzonNU() {// present elevation of the sun 1841 float Tijd1; 1842 float AZ; 1843 float Decc; 1844 float TVE; 1845 float Tijd2; 1846 float HGTE; 1847 float Hoogte; 1848 float ZZ; 1849 float Lgt; 1850 float BB; 1851 float HGT; 1852 Tijd1 = timevalue(0) * 24; 1853 //Serial.println(Tijd1,6); 1854 Lgt = LengteGraad(LG); 1855 Tijd1 = Tijd1 - WT - Lgt; 1856 Schrikkeljaar(); 1857 AZ = TotaalDagen(month); 1858 AZ = AZ - Lentepunt + monthDay; 1859 Decc = Declinatie(AZ, Dagen); 1860 AZ = AZ + Lentepunt; 1861 TVE = Tijdvereffening(AZ); 1862 Tijd1 = Tijd1 - TVE; 1863 Tijd2 = (Tijd1 * 15.0) - 180.0; 1864 HGTE = (SINUS(BG) * SINUS(Decc)) + (COSINUS(BG) * COSINUS(Decc) * COSINUS(Tijd2)); 1865 Hoogte = ARCSINUS(HGTE); 1866 // Serial.print("hoogte: "); 1867 //Serial.println(Hoogte); 1868 ZZ = Hoogte; 1869 ZZ = abs(ZZ); // abs = absoluut 1870 HGT = (SINUS(BG) * SINUS(Decc)) + (COSINUS(BG) * COSINUS(Decc)); 1871 BB = ARCSINUS(HGT); 1872 1873 Factor(BB * 100, true); 1874 display1(19, 255, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1875 1876 Factor(ZZ * 100, true); 1877 if (Hoogte >= 0) { 1878 display2(145, 255, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1879 } else { 1880 display2(145, 127, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1881 } 1882} 1883// when you put - 1 after "]", the display dot will be lit 1884//---------------------------------------------------------------- 1885void SchStand() {// tilt of the earth 1886 float BB; 1887 float BB2; 1888 float AZ; 1889 1890 Schrikkeljaar(); 1891 AZ = TotaalDagen(month); 1892 //AZ = 345; 1893 AZ = (AZ - Lentepunt) + monthDay; 1894 BB = Declinatie(AZ, Dagen); 1895 BB2 = BB; 1896 1897 BB2 = abs(BB2); // abs = absoluut 1898 1899 1900 Factor(BB2 * 100, true); 1901 if (BB >= 0) { 1902 display1(91, 255, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1903 } else { 1904 display1(91, 127, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1905 } 1906 1907 Factor(DagLengte * 100, true); 1908 display2(67, 143, Data1[DT], Data1[HT] - 1, Data1[TT], Data1[EH]); 1909} 1910// when you put - 1 after "]", the display dot will be lit 1911//----------------------------------------------------- 1912float LengteGraad(float Lg1) {// longitude 1913 float Lgt; 1914 1915 while (Lg1 >= 15) { 1916 Lg1 -= 15; 1917 } 1918 Lgt = (15 - Lg1); 1919 Lgt = Lgt / 15; 1920 return Lgt; 1921} 1922
Comments
Only logged in users can leave comments