jg53fn55
Published © GPL3+

Binary/decimal clock

Decimal/binary clock that also displays sun set or sun rise and other functions.

IntermediateShowcase (no instructions)656
Binary/decimal clock

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
or use atmega328
×1
16 MHz Crystal
16 MHz Crystal
×1
Capacitor 10 pF
Capacitor 10 pF
×2
5 mm LED: Red
5 mm LED: Red
×5
5 mm LED: Green
5 mm LED: Green
×34
Resistor 220 ohm
Resistor 220 ohm
×57
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
any display with Common Anode
×6
Shift Register- Parallel to Serial
Texas Instruments Shift Register- Parallel to Serial
use SN74595
×9
DS3231MPMB1 Peripheral Module
Maxim Integrated DS3231MPMB1 Peripheral Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

SchematicTdisplayWith39Leds

Digital and normal time

Code

Digital clock

Arduino
Binary and normal time
#include <Wire.h>
#define PI 3.1415926535897932384626
#define DEG_TO_RAD 0.0174532925199
#define RAD_TO_DEG 57.295779513082

#include "Button2.h"; //  https://github.com/LennartHennigs/Button2
#include "Rotary.h";
#define ROTARY_PIN1  A0
#define ROTARY_PIN2 A1
#define BUTTON_PIN  A2
#define CLICKS_PER_STEP 4   // this number depends on your rotary encoder
#define MIN_POS         -100
#define MAX_POS         100
#define START_POS       0
#define INCREMENT       1   // this number is the counter increment on each step
Button2 bt;
Rotary rt;
const byte interruptPin = 2;
////Pin connected to Serial in of TLC5916
byte dataPinR = 3;

//Pin connected to Latch of TLC5916
byte latchPinR = 4;

//Pin connected to ClockPulse of TLC5916
byte clockPinR = 5;

byte dataPin1 = 6;
byte latchPin1 = 7;
byte clockPin1 = 8;
byte SW1 = 9;
byte SW2 = 10;
byte SW3 = 11;
byte SW4 = 12;

byte LED1[10] = {
  5, 207, 35, 131, 201, 145, 17, 199, 1, 129
};

byte LED2[10] = {// dot is aan
  4, 206, 34, 130, 200, 144, 16, 198, 0, 128
};
byte LDIG1[10] = {
  0, 2, 6, 14, 30, 62, 126, 254, 254, 254
};
byte LDIG2[10] = {
  0, 0, 0, 0, 0, 0, 0, 0, 2, 6
};
byte LDIGdot1[10] = {
  0, 2, 4, 8, 16, 32, 64, 128, 0, 0
};
byte LDIGdot2[10] = {
  0, 0, 0, 0, 0, 0, 0, 0, 2, 4
};
byte Schrikkel = 0;
int Dagtotaal[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int DagtotaalS[12] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
byte DagMaand[13] = {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
byte DagMaandS[13] = {31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
byte Maan[20] = {2, 13, 24, 5, 16, 27, 8, 19, 30, 11, 22, 3, 14, 25, 6, 17, 29, 10, 21};
// epacta getallen
//eerste getal 2 is het jaar 2017
//elk jaar verschuift 11, behalve eens in de 19 jaar, dan 12.
// laatste was in 2014 dan in 2033, en in 2052
byte AR;
int second;
int minute;
int hour;
int weekday;
int monthDay;
int month;
int year;
int Sjaar;
byte Test;
byte test1;
byte test2;
byte test3;
byte test4;
byte a = 0;
byte b = 0;
byte c = 0;
byte d = 0;
byte e = 0;
byte f = 0;
byte g = 0;
byte h = 0;
byte i = 0;
byte j = 0;
byte k = 0;
byte m = 0;
byte WT = 1;
long HDT;
long TDT;
long DT;
long HT;
long TT;
long EH;
byte ddd[17];
int Lentepunt;
int Dagen;
float ZonOp;
float ZonOnder;
float DagLengte;
float BG = 52.9;
float LG = 4.75;
float BB;
float BB2;
float AZ;
float Decc;
long DS;
long uur;
long DR;
float ZZ;
float TVE;
float DM;
float Lgt;
float Tijd1;
float Tijd2;
float HGTE;
int counter = 0;
volatile int encoderPos = 0;
boolean buttonPressed = 0; // a flag variable
volatile byte secondsInterrupt = 0;
//----------------------------------------------------------------------
void setup() {

  //set pins to output because they are addressed in the main loop
  pinMode(latchPinR, OUTPUT);
  pinMode(clockPinR, OUTPUT);
  pinMode(dataPinR, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  pinMode(latchPin1, OUTPUT);
  pinMode(clockPin1, OUTPUT);
  pinMode(dataPin1, OUTPUT);
  pinMode(SW1, INPUT_PULLUP);
  pinMode(SW2, INPUT_PULLUP);
  pinMode(SW3, INPUT_PULLUP);
  pinMode(SW4, INPUT_PULLUP);
 
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(interruptPin), secondsRTC, FALLING);
  Wire.begin();   // begin I2C routine

  bt.begin(BUTTON_PIN);
  bt.setPressedHandler(pressed);
  bt.setReleasedHandler(released);

  rt.begin(ROTARY_PIN1, ROTARY_PIN2, CLICKS_PER_STEP, MIN_POS, MAX_POS, START_POS, INCREMENT);
  rt.setLeftRotationHandler(showDirection);
  rt.setRightRotationHandler(showDirection);
  zet_24uurmode();
  SQW1hzOn();
    
  TijdDigReset();
  Tijdreset ();
  delay(2000);
  TijdUitlezen();
  Ledtest ();
  TijdDigTest();
  Tijdreset ();
  delay(2000);
}
//------------------------------------------------------------------
void secondsRTC(void) {                 // *** ISR iedere seconde ***
  secondsInterrupt = 1;                 // ISR vlag = 1 : er was een 'seconds' interrupt.
}
//------------------------------------------------------------------------
void TijdUitlezen() {
  second = lees_seconde();
  minute = lees_minuut();
  hour = lees_uur();
  weekday = lees_dagweek();  //0-6 -> sunday - Saturday
  monthDay = lees_datum();
  month = lees_maand();
  year = lees_jaar();
  //Serial.println(month);
  Sjaar = year;
  Factor(minute, false);
  c = EH;
  d = TT;
  // uur uitlezen///
  Factor(hour, false);
  e = EH;
  f = TT;
  // dag uitlezen///
  Factor(monthDay, false);
  g = EH;
  h = TT;
  // maand uitlezen///
  //Serial.println(month);
  Factor(month, false);
  i = EH;
  j = TT;
  // jaar uitlezen///
  Factor(year, false);
  k = EH;
  m = TT;
  //Serial.println(second);
}
//------------------------------------------------------------------------
byte AgingRead() {
  return leesroutine(16);// data is two's complement
}
//------------------------------------------------------------------------
void zet_24uurmode() {// set 24 hour mode
  byte uurreg;
   uurreg = leesroutine(2);
  if (uurreg > 64){// bit 6 = 64, set to zero
    uurreg = uurreg - 64;
     instelroutine(2, uurreg);
  }
}

//------------------------------------------------------------------------
byte lees_seconde() { // read seconds
  return  BcdToDec(leesroutine(0));
}
//------------------------------------------------------------------------
byte lees_minuut() { //read minute
  return  BcdToDec(leesroutine(1));
}
//------------------------------------------------------------------------
byte lees_uur() {  // read hour
  return  BcdToDec(leesroutine(2));
}
//------------------------------------------------------------------------
byte lees_dagweek() { // read DOW
  return  BcdToDec(leesroutine(3));
}
//------------------------------------------------------------------------
byte lees_datum() { // read day of month
  return  BcdToDec(leesroutine(4));
}
//------------------------------------------------------------------------
byte lees_maand() { // read month
  return  BcdToDec(leesroutine(5));
}

//------------------------------------------------------------------------
byte lees_jaar() {  // read year
  return  BcdToDec(leesroutine(6));
}
//------------------------------------------------------------------------
byte BcdToDec(byte val) {
  return  (val / 16 * 10) + (val % 16);// bcd to decimal
}
//------------------------------------------------------------------------
byte leesroutine(byte adres) {// read register of RTC

  Wire.beginTransmission(0x68); // adress RTC DS1307 or DS3231
  Wire.write(adres);       // address  register DS3231
  Wire.endTransmission();       // einde I2C routine
  Wire.requestFrom(0x68, 1);
  return  Wire.read();
}
//------------------------------------------------------------------------
void instelroutine(byte adres, byte data1) {// set register of RTC
  Wire.beginTransmission(0x68); // adress RTC DS3231
  Wire.write(adres);       // address register DS3231
  Wire.write(data1);
  Wire.endTransmission();       // einde I2C routine
}

//------------------------------------------------------------------------
byte decToBcd(byte val) {
  return ((val / 10 * 16) + (val % 10));
}
//------------------------------------------------------------------------
void Agingadjust(byte data1) {// fine adjust the frequency of the RTC

  instelroutine(16, data1);// data is two's complement
  /*
     Positive aging values add capacitance to the array, slowing  the
     oscillator  frequency.  Negative  values  remove  capacitance from the array,
     increasing the oscillator frequency. The change in ppm per LSB is different
     at different temperatures. The frequency vs. temperature curve is shifted by
     the  values  used  in  this  registert.  At  +25C,  one  LSB  typically
     provides about 0.1ppm change in frequency.
  */
}
//------------------------------------------------------------------------
void SQW1hzOn() {// switch the 1 Hz SQW on
  instelroutine(14, 0);
}
//------------------------------------------------------------------------
void zet_jaar(byte data1) { // set year
  instelroutine(6, decToBcd(data1));
}
//------------------------------------------------------------------------
void zet_maand(byte data1) { // set month
  instelroutine(5, decToBcd(data1));
}
//------------------------------------------------------------------------
void zet_datum(byte data1) { // set day of month
  instelroutine(4, decToBcd(data1));
}
//------------------------------------------------------------------------
void zet_dagweekin(byte data1) { // set DOW
  instelroutine(3, decToBcd(data1));
}
//------------------------------------------------------------------------
void zet_uur(byte data1) { // set hour
  instelroutine(2, decToBcd(data1));
}
//------------------------------------------------------------------------
void zet_minuut(byte data1) { // set minute
  instelroutine(1, decToBcd(data1));
}
//------------------------------------------------------------------------
void zet_seconde(byte data1) { // set second
  instelroutine(0, decToBcd(data1));
}
//---------------------------------------------------------------

void Schrikkeljaar () {

  Sjaar %= 4; // %= is remainder --------

  if (Sjaar  == 0)
  {
    Schrikkel = 1;
    Lentepunt = 81;
    Dagen = 366;
  }
  else
  {
    Schrikkel = 0;
    Lentepunt = 80;
    Dagen = 365;
  }
//-------------------------------------------------
}
void showDirection(Rotary& rt) {
  //Serial.println(rt.getDirection());

  counter = rt.getDirection();
  if (counter == 255)
  {
    counter = -1;
  }
  else
  {
    counter = 1;
  }
  encoderPos += counter;
  //Serial.println(encoderPos);
}


//--------------------------------------------------------
void pressed(Button2& btn) {
  //Serial.print("pressed ");
  buttonPressed = 1;
  //Serial.println(buttonPressed);
}
void released(Button2& btn) {
  // Serial.print("released: ");
  buttonPressed = 0;
  //Serial.println(buttonPressed);
}



// --------------------------------------------------------------
void Factor (long Getal, bool graden) {
  long Test;
  //Serial.println(Getal);
  Test = Getal;
  HDT = Test / 100000;
  Test = Test - (HDT * 100000);

  TDT = Test / 10000;
  Test = Test - (TDT * 10000);

  DT = Test / 1000;
  Test = Test - (DT * 1000);


  HT = Test / 100;
  Test = Test - (HT * 100);

  if (graden == true) {
    Test = Test * 0.6;
  }
  TT = Test / 10;
  Test = Test - (TT * 10);

  EH = Test;

}

//---------------------------------------------
void readtime() {

  second = lees_seconde();// read seconds
  // seconde uitlezen///
  Factor (second, false);
  a = EH;
  b = TT;

  if (second == 0) {
     minute = lees_minuut();// read minutes
    // minuut uitlezen///
    Factor (minute, false);
    c = EH;
    d = TT;
  }

  if (minute == 0 & second == 0) {
    hour = lees_uur();// read hour
    // uur uitlezen///
    Factor (hour, false);
    e = EH;
    f = TT;
  }

  if (hour == 0 & second == 0) {
     weekday = lees_dagweek();  //0-6 -> sunday - Saturday
    monthDay = lees_datum();// read day of month
    month = lees_maand();// read month
    year = lees_jaar();// read year

    // dag uitlezen///
    Factor (monthDay , false);
    g = EH;
    h = TT;
    // maand uitlezen///
    Factor (month , false);
    i = EH;
    j = TT;
    Factor (year , false);
    k = EH;
    m = TT;
  }


}
//---------------------------------------------------------

void loop() {


  test1 = digitalRead(SW1);
  test2 = digitalRead(SW2);
  test3 = digitalRead(SW3);
  test4 = digitalRead(SW4);
  Test = test4 * 8;
  Test += test3 * 4;
  Test += test2 * 2;
  Test += test1;

  if (secondsInterrupt == 1) {         // **** doe als ISR vlag = 1  ****
    readtime();                   // de subroutine die iedere seconde de tijd registers leest.
    secondsInterrupt = 0;            // zet ISR vlag terug naar '0'
    dddInstellen(16);
  }

  switch (Test) {
    case 0:// 0000
      if (ddd[0] == 1)
      {
        Tijd();//time
        dddInstellen(0);
      }
      TijdDig1();//time digital
      break;
    case 1:// 0001
      if (ddd[1] == 1)
      {
        Datum ();
        dddInstellen(1);
      }
      TijdDig1();
      break;
    case 2:// 0010
      if (ddd[2] == 1)
      {
        Tijd();
        dddInstellen(2);
      }
      TijdDig2();
      break;
    case 3:// 0011
      if (ddd[3] == 1)
      {
        Tijd();
        dddInstellen(3);
      }
      TijdDig3();
      break;
    case 4:// 0100
      if (ddd[4] == 1)
      {
        if (hour >= 0 & hour < 8) {
          Tijdreset ();
        }
        else
        {
          Tijd();
        }
        dddInstellen(4);
      }
      break;
    case 5:// 0101
      if (ddd[5] == 1)
      {
        DagNR();
        dddInstellen(5);
      }
      TijdDig1();
      break;
    case 6:// 0110
      if (ddd[6] == 1)
      {
        DagSEC();
        dddInstellen(6);
      }
      TijdDig1();
      break;
    case 7:// 0111
      if (ddd[7] == 1)
      {
        Tijdreset ();
        dddInstellen(7);
      }
      TijdDig1();
      break;
    case 8:// 1000
      if (ddd[8] == 1)
      {
        Tijd();
        dddInstellen(8);
      }
      TijdDigdot();
      break;
    case 9:// 1001
      Adjust();
      break;
    case 10:// 1010
      if (ddd[10] == 1)
      {
        Tijdreset ();
        dddInstellen(10);
      }
      TijdDig3();
      break;
    case 11:// 1011
      if (ddd[11] == 1)
      {
        MinutenJaar();
        dddInstellen(11);
      }
      TijdDig1();
      break;
    case 12:// 1100
      if (ddd[12] == 1)
      {
        Zonsopgang();
        dddInstellen(12);
      }
      TijdDig1();
      break;
    case 13:// 1101
      if (ddd[13] == 1)
      {
        Zonsondergang();
        dddInstellen(13);
      }
      TijdDig1();
      break;
    case 14:// 1110
      if (ddd[14] == 1)
      {
        LCDAzimuth();
        dddInstellen(14);
      }
      TijdDig1();
      break;
    case 15:// 1111
      if (ddd[15] == 1)
      {
        HzonNU();
        dddInstellen(15);
      }
      TijdDig1();
      break;
  }


}

//--------------------------------------------------------------------------------
void dddInstellen(byte een) {
  for (byte x = 0 ; x < 16; x++)
  {
    ddd[x] = 1;// alles op 1 zetten
  }
  ddd[een] = 0;// 1 van de 16 op 0 zetten, zodat de routine 1 maal doorlopen wordt
}
//-----------------------------------------------------------
void Adjust() {

  rt.loop();
  bt.loop();
  if (encoderPos < 0) {
    encoderPos = 0;
  }
  if (encoderPos > 7) {
    encoderPos = 7;
  }
  switch (encoderPos) {
    case 0 :
      DisplayAdjust();
      break;
    case 1:
      Displaykeuze1(251);
      if (encoderPos == 1 && buttonPressed == 1) {
        encoderPos = 0;
        AdjustUUR();
      }
      break;
    case 2:
      DisplaykeuzeWT(251);
      if (encoderPos == 2 && buttonPressed == 1) {
        encoderPos = 0;
        AdjustWT();
      }
      break;
    case 3:
      Displaykeuze2(251);
      if (encoderPos == 3 && buttonPressed == 1) {
        encoderPos = 0;
        AdjustMIN();
      }
      break;
  
     case 4:
      Displaykeuze4(251);
      if (encoderPos == 4 && buttonPressed == 1) {
        encoderPos = 0;
        AdjustDAG();
      }
      break;
    case 5:
      Displaykeuze5(251);
      if (encoderPos == 5 && buttonPressed == 1) {
        encoderPos = 0;
        AdjustMND();
      }
      break;
    case 6:
      Displaykeuze6(251);
      if (encoderPos == 6 && buttonPressed == 1) {
        encoderPos = 0;
        AdjustYR();
      }
      break;
    case 7:
      
      AR = AgingRead();
      Displaykeuze8(AR);
      if (encoderPos == 7 && buttonPressed == 1) {
        encoderPos = 0;
        AdjustAging();
      }
      break;
  }
}
//-------------------------------------------------------------
void DDP (int D1, int D2, int D3, int D4, int D5, int D6) {

  digitalWrite(latchPin1, LOW);
  shiftOut(dataPin1, clockPin1, MSBFIRST, D1);
  shiftOut(dataPin1, clockPin1, MSBFIRST, D2);
  shiftOut(dataPin1, clockPin1, MSBFIRST, D3);
  shiftOut(dataPin1, clockPin1, MSBFIRST, D4);
  shiftOut(dataPin1, clockPin1, MSBFIRST, D5);
  shiftOut(dataPin1, clockPin1, MSBFIRST, D6);
  digitalWrite(latchPin1, HIGH);

}
//-------------------------------------------------------------
void DisplayAdjust() {
  DDP(57, 145, 13, 15, 11, 65);
}

//-------------------------------------------------------------
void AdjustUUR() {
  int exx = 0;
  Displaykeuze1(179);
  encoderPos = 0;
  buttonPressed = 0;
  delay(1000);
  while (exx == 0) {
   
   
    //Serial.println (encoderPos);
    if (encoderPos == 0) {
      Displaykeuze1(251);// uur
    }
    //-----------------
     rt.loop(); 
     bt.loop();

    if ( encoderPos > 1) {
      hour = hour + 1;
      if (hour == 24) {
        hour = 0;
      }
      Factor (hour, false);
      e = EH;
      f = TT;
      Displaykeuze1(247);// uur
      encoderPos = 1;

    }
   
    // --------------------------
    if ( encoderPos < -1) {
      hour = hour - 1;
      if (hour < 0) {
        hour = 23;
      }
      Factor (hour, false);
      e = EH;
      f = TT;
      Displaykeuze1(191);// uur
      encoderPos = -1;

    }
    if (buttonPressed == 1 & encoderPos != 0) {
     zet_uur(hour);// set hour
      Displaykeuze1(183);// uur
      encoderPos = 0;
      exx = 1;
    }
  }
}
// ------------------------------------------------------
void Displaykeuze1(int x) {
  DDP(LED1[e], LED1[f], x, 123, 31, 31);
}
//-------------------------------------------------------------
void AdjustWT() {
  
  int exx = 0;
  //int Zt ;
  //Zt = WT;
  DisplaykeuzeWT(179);
  delay(1000);
  while (exx == 0) {
   
   
    //Serial.println (encoderPos);
    if (encoderPos == 0) {
      DisplaykeuzeWT(251);
    }
    //-----------------
     rt.loop();
     bt.loop();

    if ( encoderPos > 1) {
      WT = 1;
      DisplaykeuzeWT(247);
        encoderPos = 1;

    }
  
    // --------------------------
    if ( encoderPos < -1) {

      WT = 0;
      DisplaykeuzeWT(191);
      encoderPos = -1;

    }
    if (buttonPressed == 1 & encoderPos != 0) {
      DisplaykeuzeWT(183);
      WT = 0;
     
      encoderPos = 0;
      exx = 1;
    }
  }
}


// ------------------------------------------------------
void DisplaykeuzeWT(int x) {
  DDP(LED1[WT], 255, x, 255, 57, 57);
}
//-----------------------------------------------------------
void AdjustMIN() {
  int exx = 0;
 
  Displaykeuze2(179);
  encoderPos = 0;
  buttonPressed = 0;
  delay(1000);

  while (exx == 0) {

   
   
    //Serial.println (encoderPos);
    if (encoderPos == 0) {
      Displaykeuze2(251);// min
    }
    //-----------------
     rt.loop(); 
     bt.loop();

    if ( encoderPos > 1) {
      minute = minute + 1;
      if (minute == 60) {
        minute = 0;
      }
      Factor (minute, false);
      c = EH;
      d = TT;
      Displaykeuze2(247);// min
        encoderPos = 1;
    }
    
    // --------------------------
    if ( encoderPos < -1) {
      minute = minute - 1;
      if (minute < 0) {
        minute = 59;
      }
      Factor (minute, false);
      c = EH;
      d = TT;
      Displaykeuze2(191);// uur
      encoderPos = -1;
    }
    if (buttonPressed == 1 & encoderPos != 0) {
      zet_seconde(0);
      zet_minuut(minute);
      Displaykeuze2(183);// min
     
      encoderPos = 0;
      exx = 1;
    }

  }
}

// ------------------------------------------------------
void Displaykeuze2(int x) {
  DDP(LED1[c], LED1[d], x, 91, 207, 69);
}
//----------------------------------------------------------
void AdjustDAG() {
  int exx = 0;
 
  Displaykeuze4(179);
  encoderPos = 0;
  buttonPressed = 0;
  delay(1000);

  while (exx == 0) {

   
  

    if (encoderPos == 0) {
      Displaykeuze4(251);// min
    }
    //-----------------
     rt.loop();
     bt.loop();

    if ( encoderPos > 1) {
      monthDay = monthDay + 1;
      if (monthDay == 32) {
        monthDay = 1;
      }
      Factor (monthDay , false);
      g = EH;
      h = TT;
      Displaykeuze4(247);// min
           encoderPos = 1;
    }
    
    // --------------------------
    if ( encoderPos < -1) {
      monthDay = monthDay - 1;
      if (monthDay == 0) {
        monthDay = 31;
      }
      Factor (monthDay , false);
      g = EH;
      h = TT;
      Displaykeuze4(191);// uur
     
      encoderPos = -1;
    }
    if (buttonPressed == 1 & encoderPos != 0) {
      zet_datum(monthDay);
      Displaykeuze4(183);// min
     
      encoderPos = 0;
      exx = 1;
    }

  }
}
// ------------------------------------------------------
void Displaykeuze4(int x) {
  DDP(LED1[g], LED1[h], x, 137, 65, 11);
}
//-------------------------------------------------------
void AdjustMND() {
  int exx = 0;
 
  Displaykeuze5(179);
  encoderPos = 0;
  buttonPressed = 0;


  while (exx == 0) {

    

  
    if (encoderPos == 0) {
      Displaykeuze5(251);// min
    }
    //-----------------
     rt.loop();
    bt.loop();

    if ( encoderPos > 1) {
      month = month + 1;
      if (month == 13) {
        month = 1;
      }
      Factor (month , false);
      i = EH;
      j = TT;
      Displaykeuze5(247);// min
           encoderPos = 1;
    }
    
    // --------------------------
    if ( encoderPos < -1) {
      month = month - 1;
      if (month == 0) {
        month = 12;
      }

      Factor (month , false);
      i = EH;
      j = TT;
      Displaykeuze5(191);// uur
           encoderPos = -1;
    }
    if (buttonPressed == 1 & encoderPos != 0) {
      zet_maand(month);// set month
      Displaykeuze5(183);
     
      encoderPos = 0;
      exx = 1;
    }

  }
}
// ------------------------------------------------------
void Displaykeuze5(int x) {
  DDP(LED1[i], LED1[j], x, 11, 91, 69);
}
//------------------------------------------------------
void AdjustYR() {
  int exx = 0;
 

  Displaykeuze6(179);
  encoderPos = 0;
  buttonPressed = 0;

  if (year > 2000) {
    year = year - 2000;
  }

  while (exx == 0) {

      if (encoderPos == 0) {
      Displaykeuze6(251);// min
    }
    //-----------------
     rt.loop();
     bt.loop();
    if ( encoderPos > 1) {
      year = year + 1;
      if (year > 99) {
        year = 0;
      }
      Factor (year , false);
      k = EH;
      m = TT;
      Displaykeuze6(247);// min
     
      encoderPos = 1;
    }
   
    // --------------------------
    if ( encoderPos < -1) {
      year = year - 1;
      if (year < 0) {
        year = 99;
      }
      Factor (year , false);
      k = EH;
      m = TT;
      Displaykeuze6(191);// uur
      
      encoderPos = -1;
    }
    if (buttonPressed == 1 & encoderPos != 0) {
     
      zet_jaar(year);// set year
      Displaykeuze6(183);
      
      encoderPos = 0;
      exx = 1;
    }

  }
}
// ------------------------------------------------------
void Displaykeuze6(int x) {
  DDP(LED1[k], LED1[m], x, 255, 123, 137);
}
//------------------------------------------------------
void AdjustAging() {
  int exx = 0;
  encoderPos = 0;
  buttonPressed = 0;

  Displaykeuze8(AR);

  AR = AgingRead();

  while (exx == 0) {
    Displaykeuze8(AR);
   


    if (encoderPos == 0) {
      Displaykeuze8(AR);

    }
    //-----------------
     rt.loop(); 
     bt.loop();
    if (encoderPos > 1) {
      AR = AR + 1;
      if (AR > 127) {
        AR = 0;
      }

      Displaykeuze8(AR);
      encoderPos = 1;
    }
   
    // --------------------------
    if (encoderPos < -1) {
      AR = AR - 1;
      if (AR < -128) {
        AR = 0;
      }

      Displaykeuze8(AR);
      encoderPos = -1;
    }
    if (buttonPressed == 1 & encoderPos != 0) {
      Agingadjust(AR);
      Displaykeuze8(AR);
      encoderPos = 0;
      buttonPressed = 0;
      exx = 1;
    }

  }
}
// ------------------------------------------------------
void Displaykeuze8(byte ARR) {
  int RR;
  // aging register of RTC uses two's complement, a negative number is from 128 to 255
  RR = ARR;

  if (RR >= 0 & RR < 128) {
    Factor(RR, false);
    DDP(LED1[EH], LED1[TT], LED1[HT], 255, 255, 65);
  }
  else
  {
    RR = RR - 256;
    RR = abs(RR);
    Factor(RR, false);
    DDP(LED1[EH], LED1[TT], LED1[HT], 251, 255, 65);

  }

}
//-------------------------------------------------------------
void Tijd() {
  DDP(LED1[a], LED1[b], LED1[c], LED1[d], LED2[e], LED1[f]);
}
//-------------------------------------------------------------
void Tijdreset () {
  DDP(255, 255, 255, 255, 255, 255);
}
//-------------------------------------------------------------
void DDP2(int D1, int D2, int D3, int D4) {
  digitalWrite(latchPinR, LOW);
  shiftOut(dataPinR, clockPinR, MSBFIRST, D1);// kolom
  shiftOut(dataPinR, clockPinR, MSBFIRST, D2);// rij2
  shiftOut(dataPinR, clockPinR, MSBFIRST, D3);//rij1
  digitalWrite(latchPinR, HIGH);
  delayMicroseconds(D4);
}
//-------------------------------------------------------------
void TijdDig1() {
  DDP2(191, LDIG2[a], LDIG1[a], 14);
  DDP2(223, 0, LDIG1[b], 14);
  DDP2(239, LDIG2[c], LDIG1[c], 14);
  DDP2(247, 0, LDIG1[d], 14);
  DDP2(251, LDIG2[e], LDIG1[e], 14);
  DDP2(253, 0, LDIG1[f], 14);
  DDP2(127, 0, 0 , 14);
}
//-------------------------------------------------------------
void TijdDigdot() {
  DDP2(191, LDIGdot2[a], LDIGdot1[a], 14 );
  DDP2(223, 0, LDIGdot1[b], 14 );
  DDP2(239, LDIGdot2[c], LDIGdot1[c], 14 );
  DDP2(247, 0, LDIGdot1[d], 14 );
  DDP2(251, LDIGdot2[e], LDIGdot1[e], 14);
  DDP2(253, 0, LDIGdot1[f], 14 );
  DDP2(127, 0, 0, 14 );
}
//-------------------------------------------------------------
void TijdDig2() {
  DDP2(191, 0, a * 2, 14 ); // 191 = kolom 6(255-64) seconden eenheid
  DDP2(223, 0, b * 2, 14); // 223 = kolom 5 (255-32) seconden tiental
  DDP2(239, 0, c * 2, 14); // 239 = kolom 4 (255-16) minuten eenheid
  DDP2(247, 0, d * 2, 14); // 247 = kolom 3 minuten tiental
  DDP2(251, 0, e * 2, 14); // 251 = kolom 2 uren eenheid
  DDP2(253, 0, f * 2, 14); // 253 = kolom 1 uren tiental
  DDP2(127, 0, 0 , 14); // extra data zodat laatste led minder fel gaat branden
}
//-------------------------------------------------------------
void TijdDig3() {
  DDP2(191, 0, second * 2 , 14);
  DDP2(223, 0, 0 , 14);
  DDP2(239, 0, minute * 2 , 14);
  DDP2(247, 0, 0 , 14);
  DDP2(251, 0, hour * 2, 14);
  DDP2(253, 0, 0, 14);
  DDP2(127, 0, 0, 14);
}

//-------------------------------------------------------------
void TijdDigReset() {
  DDP2(191, 0, 0 , 14); // 191 = kolom 6(255-64) seconden eenheid
  DDP2(223, 0, 0 , 14); // 223 = kolom 5 (255-32) seconden tiental
  DDP2(239, 0, 0 , 14); // 239 = kolom 4 (255-16) minuten eenheid
  DDP2(247, 0, 0 , 14); // 247 = kolom 3 minuten tiental
  DDP2(251, 0, 0 , 14); // 251 = kolom 2 uren eenheid
  DDP2(253, 0, 0 , 14); // 253 = kolom 1 uren tiental
  DDP2(127, 0, 0 , 14); // extra data zodat laatste led minder fel gaat branden
}
//-------------------------------------------------------------
void TijdDigTest() {

  for (int z = 0; z <= 20; z++) {
    for (int x = 0; x <= 10; x++) {
      DDP2(191, LDIG2[x], LDIG1[x] , 1000);
      DDP2(223, 0, LDIG1[x] , 1000);
      DDP2(239, LDIG2[x], LDIG1[x] , 1000);
      DDP2(247, 0, LDIG1[x] , 1000);
      DDP2(251, LDIG2[x], LDIG1[x] , 1000);
      DDP2(253, 0, LDIG1[x] , 1000);
      DDP2(127, 0, 0 , 1000);
    }
  }
}
//------------------------------------------------------------------


void Datum () {
  DDP(LED1[k], LED1[m], LED1[i], LED1[j], LED2[g], LED1[h]);
}
//---------------------------------------------------------
void Ledtest () {
  for (int x = 0; x < 10; x++) {
    //Serial.println(x);
    DDP(LED1[x], LED1[x], LED1[x], LED1[x], LED2[x], LED1[x]);
    delay(400);
  }
  delay(2000);
}

// --------------------------------------------------------------
void DagNR() {
  Schrikkeljaar ();
  DR = TotaalDagen(month) +  monthDay;

  Factor (DR , false);
  DDP(LED1[EH], LED1[TT], LED1[HT], 255, 137, 11);
}
// -------------------------------------------------------------------
int TotaalDagen(int maand) { // dit is een functie
  int Dagen;
  int dag1 = maand - 1;
  if (Schrikkel == 1)
  {
    Dagen = DagtotaalS[dag1];
  }
  else
  {
    Dagen = Dagtotaal[dag1];
  }
  return Dagen;
}
//------------------------------------------------------
void DagSEC() {

  uur = hour;
  DS = (uur * 3600);
  DS += (minute * 60);
  DS += second;
  Factor (DS , false);
  DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], LED1[TDT], 255);

}
//------------------------------------------------------
void MinutenJaar() {

  uur = hour;
  Schrikkeljaar ();
  DS = TotaalDagen(month);
  DS += monthDay - 1;
  //Serial.println(DS);
  DS *= (24 * 60);
  DS += (uur * 60);
  DS += minute;
  Factor (DS , false);
  DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], LED1[TDT], LED1[HDT]);

}
//-----------------------------------------------------------------
void LEDMaan() {
  float Uur1;
  float Min1;
  float MOud;
  int Index;
  float AZ;
  float test11;
  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  Min1 = minute;
  Uur1 = hour + (Min1 / 60);
  AZ = AZ + monthDay ;
  AZ = AZ + (Uur1 / 24);
  if (year > 2000) {
    year = year - 2000;
  }
  Index = year - 17;// epactagetal ophalen
  while (Index > 18)
  {
    Index = Index - 19;
  }

  MOud = Maan[Index];

  MOud = MOud + AZ;

  while (MOud >= 29.5305885)
  {
    MOud -= 29.5305885;
  }

  Factor (MOud * 100 , false);
  DDP(91, 11, LED1[EH], LED1[TT], LED1[HT], LED1[DT]);

}
//---------------------------------------------------------
void Zonsopgang() {

  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  AZ = AZ - Lentepunt + monthDay;
  Decc = Declinatie(AZ, Dagen);
  ZonOpOnder(Decc, BG);// aanroepen routine
  Lgt = LengteGraad(LG);

  ZZ = ZonOp + Lgt;
  ZZ += WT;
  AZ += Lentepunt;

  TVE = Tijdvereffening(AZ, Dagen);

  ZZ += TVE;


  Factor (ZZ * 100 , true);
  DDP(97, 31, LED1[EH], LED1[TT], LED1[HT], LED1[DT]);

}
//---------------------------------------------------------
void Zonsondergang() {

  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  AZ = AZ - Lentepunt + monthDay ;
  Decc = Declinatie(AZ, Dagen);
  ZonOpOnder(Decc, BG);// aanroepen routine
  Lgt = LengteGraad(LG);
  ZZ = ZonOnder + Lgt;
  ZZ += WT;
  AZ += Lentepunt;

  TVE = Tijdvereffening(AZ, Dagen);

  ZZ += TVE;

  Factor (ZZ * 100 , true);
  DDP(91, 31, LED1[EH], LED1[TT], LED1[HT], LED1[DT]);

}
// -----------------------------------------------

double Declinatie(float dag, float Jaardag) {
  double DECL;
  DECL = (dag * 360.0 / Jaardag);
  DECL = SINUS(DECL);
  return DECL = DECL * 23.5;
}
//-------------------------------------------------
double ARCTANGENS(double x) {
  double XX;
  XX = x ;
  return atan(XX) * RAD_TO_DEG;
}
//-------------------------------------------------
double ARCCOSINUS(double x) {
  double XX;
  XX = x ;
  return acos(XX) * RAD_TO_DEG;
}
//-------------------------------------------------
double ARCSINUS(double x) {
  double XX;
  XX = x ;
  return asin(XX) * RAD_TO_DEG;
}
//-------------------------------------------------
double TANGENS(double x) {
  double XX;
  XX = x * DEG_TO_RAD;
  return tan(XX);
}
//-------------------------------------------------
double COSINUS(double x) {
  double XX;
  XX = x * DEG_TO_RAD;
  return cos(XX);
}
//-------------------------------------------------
double SINUS(double x) {
  double XX;
  XX = x * DEG_TO_RAD;
  return sin(XX);
}

//--------------------------------------------------
void ZonOpOnder(float decl, float brg) {
  float ZON;
  float ZonOpOn;
  float AA2 = 180.0;
  float BB2 = 15.0;
  float gr = -1.25;
  ZON = (SINUS(gr) - (SINUS(brg) * (SINUS(decl)))) / (COSINUS(brg) * COSINUS(decl));
  ZonOpOn = ARCCOSINUS(ZON);
  ZonOp = (AA2 - ZonOpOn) / BB2;
  ZonOnder = (AA2 + ZonOpOn) / BB2;
  DagLengte = ZonOnder - ZonOp;

}
//-------------------------------------------------
float Tijdvereffening(float dd, int Dagen) {
  float Tijd;
  float TVV;
  Tijd = (7.56 * SINUS((2 * 180 * (dd - 2.7)) / Dagen));
  Tijd = Tijd + (9.85 * (SINUS((4 * 180 * (10.5 + dd)) / Dagen)));
  TVV = (Tijd / 60);
  return TVV;
}
// ------------------------------------------------
void HzonNU() {
  float Hoogte;
  Tijd1 = hour + (minute / 60.0);
  Tijd1 = Tijd1 + (second / 3600.0);
  Lgt = LengteGraad(LG);
  Tijd1 = Tijd1 - WT - Lgt;
  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  AZ = AZ - Lentepunt + monthDay ;
  Decc = Declinatie(AZ, Dagen);
  AZ = AZ + Lentepunt;
  TVE = Tijdvereffening(AZ, Dagen);
  Tijd1 = Tijd1 - TVE;
  Tijd2 = (Tijd1 * 15.0) - 180.0;
  HGTE = (SINUS(BG) * SINUS(Decc)) + (COSINUS(BG) * COSINUS(Decc) * COSINUS(Tijd2));
  Hoogte = ARCSINUS(HGTE);
  // Serial.print("hoogte: ");
  //Serial.println(Hoogte);
  ZZ = Hoogte;
  ZZ = abs(ZZ);// fabs = absoluut
  Factor (ZZ * 100 , true);
  if (Hoogte >= 0) {
    DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], 255, 255);
  }
  else
  {
    DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], 251, 255);
  }

}

//----------------------------------------------------------------
void SchStand() {

  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  //AZ = 345;
  AZ = (AZ - Lentepunt) + monthDay ;
  BB = Declinatie(AZ, Dagen);
  BB2 = BB;
  BB2 = abs(BB2);// fabs = absoluut

  Factor (BB2 * 100 , true);
  if (BB >= 0) {
    DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], 255, 255);
  }
  else
  {
    DDP(LED1[EH], LED1[TT], LED1[HT], LED1[DT], 255, 251);
  }
}
//-----------------------------------------------
float Hoogte(float decl, float brg) {
  float HGT;
  float HGT2;
  HGT = (SINUS(brg) * SINUS(decl)) + (COSINUS(brg) * COSINUS(decl));
  HGT2 = ARCSINUS(HGT);
  return HGT2;
}
//--------------------------------------------------------------------------
void LCDAzimuth() {

  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  //AZ = 180;
  AZ = (AZ - Lentepunt) + monthDay ;
  Decc = Declinatie(AZ, Dagen);
  BB = Hoogte(Decc, BG);

  Factor (BB * 100 , true);
  DDP(90, 255, LED1[EH], LED1[TT], LED1[HT], LED1[DT]);

}
//-----------------------------------------------------
float LengteGraad(float Lg1) {
  float Lgt;

  while (Lg1 >= 15)
  {
    Lg1 -= 15;
  }
  Lgt = (15 - Lg1);
  Lgt = Lgt / 15;
  return Lgt;

}

Credits

jg53fn55
0 projects • 4 followers
I am retired.
Contact

Comments

Please log in or sign up to comment.