jg53fn55
Published © LGPL

Numitron clock

Numitron IV-9 clock with RTC 3231

IntermediateShowcase (no instructions)363
Numitron clock

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
High Accuracy Pi RTC (DS3231)
Seeed Studio High Accuracy Pi RTC (DS3231)
×1
Shift Register- Parallel to Serial
Texas Instruments Shift Register- Parallel to Serial
TLC5916
×4
MyOctopus i2c Barometric Air Pressure Sensor BMP280
MyOctopus i2c Barometric Air Pressure Sensor BMP280
×1
Toggle Switch, (On)-Off-(On)
Toggle Switch, (On)-Off-(On)
×4
Switch Actuator, Head for spring return push-button
Switch Actuator, Head for spring return push-button
button normal closed
×3
DC/DC Adjustable Charge Pump Voltage Converter, 1.5V to 10V in
DC/DC Adjustable Charge Pump Voltage Converter, 1.5V to 10V in
converter 5V to 3.3V
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Numitron

Clock with nice display

Code

Numitron

Arduino
Clock with nice display
// numitron clock
// made by jg53fn55
#include <SFE_BMP180.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
#define PI 3.14159265358979323
#define DEG_TO_RAD 0.01745329251
#define RAD_TO_DEG 57.2957795130
const byte interruptPin = 2;
const byte buttonUP = 3;
const byte buttonDOWN = 4;
const byte buttonSET = 13;
byte SW1 = 5;
byte SW2 = 6;
byte SW3 = 7;
byte SW4 = 8;

int OutEnable = 9;//Pin 9 connected to output enable pin 13 of TLC5916

byte latchPin1 = 10;//Pin 10 connected to Latch pin 4 of TLC5916

byte clockPin1 = 11;//Pin 11 connected to ClockPulse pin 3 of TLC5916

byte dataPin1 = 12;////Pin 12 connected to Serial in pin 2 of TLC5916
byte LedRB = A0;
byte LedRO = A1;
byte LedLB = A2;
int LedLO = A3;
byte LED1[10] = {
  222, 6, 234, 110, 54, 124, 252, 14, 254, 126
};

byte LED2[10] = {
  164, 244, 0, 228, 216, 58, 230, 190, 118, 26
};
byte LDIG[10] = {
  0, 64, 32, 96, 8, 72, 40, 104, 18, 82
};
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 in tabel Maan[20]:
//eerste getal 2 is het jaar 2017, maan is dan 2 dagen oud op 1 januari.
// volgende getal is 2018, maan is dan 13 dagen oud op 1 januari.
//elk jaar verschuift 11, behalve eens in de 19 jaar, dan 12.
// laatste was in 2014 dan in 2033, en in 2052, en in 2071 enz.
//
//----------------------english-------------------------------------------
//epacta numbers
// first number of array Maan[20] is 2. This number is the year 2017, the moon age in days is 2 on januari first
//The next number is 2018, the moon age in days is 13 also on januari first, etc..
// every year adds 11, except once in 19 years, then it wil be 12
// latest was in 2014, then in 2033 etc...
// moonage = 0 >> new moon, moonage = 14.75 >> full moon
// moonage = 7.375 >> first quarter,   moonage = 22.125 >> last quarter
// from new moon to the next new moon = 29.5 days
//
byte AR;
int second;
int minute;
int hour;
int weekday;
int monthDay;
int month;
int year;
int Sjaar;
int dag;
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;
int menu = 0;
float BG = 52.9;
float LG = 4.75;
// The variables HDT,TDT,DT,HT,TT and EH are used in the subroutine Factor();
long HDT;// hundred thousand ( when number is 123456, HDT = 1)
long TDT;// ten thousand ( when number is 123456, TDT = 2)
long DT;//thousand ( when number is 123456, DT = 3)
long HT;// hundred ( when number is 123456, HT = 4)
long TT;// tens ( when the number is 123456, TT = 5)
long EH;// unity (when the number is 123456, EH = 6)
double P ;
double T ;
int Lentepunt;
int Dagen;
float ZonOp;
float ZonOnder;
float DagLengte;
unsigned long currentMillis;
long interval = 3000;
long previousMillis = 0;

const unsigned long debounceTime = 10;  // milliseconds
byte oldButtonStateUP = HIGH;  // assume switch open because of pull-up resistor
unsigned long buttonPressTimeUP;  // when the switch last changed state
boolean buttonPressedUP = 0; // a flag variabl
byte oldButtonStateDOWN = HIGH;  // assume switch open because of pull-up resistor
unsigned long buttonPressTimeDOWN;  // when the switch last changed state
boolean buttonPressedDOWN = 0; // a flag variabl
byte oldButtonStateSET = HIGH;  // assume switch open because of pull-up resistor
unsigned long buttonPressTimeSET;  // when the switch last changed state
boolean buttonPressedSET = 0; // a flag variabl
volatile byte secondsInterrupt = 0;
//-------------------------------------------------------------------
void setup() {
  //set pins to output because they are addressed in the main loop
  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);
  pinMode(OutEnable, OUTPUT);
  pinMode(LedRB, OUTPUT);
  pinMode(LedRO, OUTPUT);
  pinMode(LedLB, OUTPUT);
  pinMode(LedLO, OUTPUT);
  pinMode(buttonDOWN, INPUT_PULLUP);
  pinMode(buttonUP, INPUT_PULLUP);
  pinMode(buttonSET, INPUT_PULLUP);
  Serial.begin(9600);
  Wire.begin();
  Zet_24uurmode();
  SQW1hzOn();
  attachInterrupt(digitalPinToInterrupt(interruptPin), secondsRTC, FALLING);
  digitalWrite(OutEnable, 1);
  NormalMode();

  TijdUitlezen();
  bool status;
    // default settings
  // (you can also pass in a Wire library object like &Wire2)
  status = bmp.begin();
  // if (!bmp.begin()) {
  //   //Serial.println("Could not find a valid BMP085 sensor, check wiring!");
  //  DDP(248, 160, 160, 6, 254, 222);
  //  delay(4000);
  // }
  Ledtest ();
}
//------------------------------------------------------------------
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();
  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///
  Factor (month , false);
  i = EH;
  j = TT;


  // jaar uitlezen///
  Factor (year , false);
  k = EH;
  m = TT;

  // RTC.setHours(Hour);// uur instellen
  //RTC.setSeconds(Second);// seconden instellen
  //Serial.println(second);
}

//------------------------------------------------------------------------
byte AgingRead() {
  return leesroutine(16);
}
//------------------------------------------------------------------------
void Zet_24uurmode() {// set 24 hour mode
  byte uurreg;
  uurreg = leesroutine(2);
  if (uurreg > 64) { // bit 6 = 64 (24 hour bit), 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);
  /*
     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_dagweek(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.0;
    Dagen = 366.0;
  }
  else
  {
    Schrikkel = 0;
    Lentepunt = 80.0;
    Dagen = 365.0;
  }

}


// --------------------------------------------------------------
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;
      // jaar uitlezen///
    Factor (year , false);
    k = EH;
    m = TT;
  }

}

//---------------------------------------------------------
void loop() {
  byte test;
  // NormalMode();
  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'
  }
  byte test1 = digitalRead(SW1);
  byte test2 = digitalRead(SW2);
  byte test3 = digitalRead(SW3);
  byte test4 = digitalRead(SW4);
  test = test4 * 8;
  test += test3 * 4;
  test += test2 * 2;
  test += test1;

  switch (test) {
    case 0://0000
      Tijd();
      break;
    case 1://0001
      Datum();
      break;
    case 2://0010
      LuchtDruk();
      break;
    case 3://0011
      LCDTemp();
      break;
    case 4://0100
      MinutenJaar();
      break;
    case 5://0101
      DagNR();
      break;
    case 6://0110
      NachtMode();
      break;
    case 7://0111
      TijdZS();
      break;
    case 8://1000
      Adjust();
      break;
    case 9://1001
      DagSEC();
      break;
    case 10://1010
      LEDMaan();
      break;
    case 11://1011
      TijdDig();
      break;
    case 12://1100
      Zonsopgang();
      break;
    case 13://1101
      Zonsondergang();
      break;
    case 14://1110
      LCDAzimuth();
      break;
    case 15://1111
      HzonNU();
      break;
  }
  //============een keer per 3 seconden sensor uitlezen ===========================
  currentMillis = millis();
  if (currentMillis - previousMillis > interval)
  {
    previousMillis = currentMillis;

    SensorLDUitlezen();

  }

}
//--------------------------------------------------------------------------
void SensorLDUitlezen() {
  T = bmp.readTemperature();
  P = bmp.readPressure();

}
//--------------------------------------------------------------------------
void DDP(int D1, int D2, int D3, int D4, int D5, int D6) {
  digitalWrite(latchPin1, HIGH);
  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, LOW);
  delay(100);
}
//------------------------------------------------------------------------------------
void buttonread() {
  byte buttonStateUP = digitalRead (buttonUP);
  if (buttonStateUP != oldButtonStateUP) {
    if (millis () - buttonPressTimeUP >= debounceTime) { // debounce
      buttonPressTimeUP = millis ();  // when we closed the switch
      oldButtonStateUP =  buttonStateUP;  // remember for next time
      if (buttonStateUP == LOW) {
        //  Serial.println ("Button closed"); // DEBUGGING: print that button has been closed
        buttonPressedUP = 1;
        menu = menu + 1;
        //Serial.print("menu ");
        // Serial.println(menu);
      }
      else {
        // Serial.println ("Button opened"); // DEBUGGING: print that button has been opened
        buttonPressedUP = 0;
      }
    }  // end if debounce time up
  } // end of state change

  byte buttonStateDOWN = digitalRead (buttonDOWN);
  if (buttonStateDOWN != oldButtonStateDOWN) {
    if (millis () - buttonPressTimeDOWN >= debounceTime) { // debounce
      buttonPressTimeDOWN = millis ();  // when we closed the switch
      oldButtonStateDOWN =  buttonStateDOWN;  // remember for next time
      if (buttonStateDOWN == LOW) {
        //  Serial.println ("Button closed"); // DEBUGGING: print that button has been closed
        buttonPressedDOWN = 1;
        menu = menu - 1;
        //Serial.print("menu ");
        //Serial.println(menu);
      }
      else {
        // Serial.println ("Button opened"); // DEBUGGING: print that button has been opened
        buttonPressedDOWN = 0;
      }
    }  // end if debounce time up
  } // end of state change


  byte buttonStateSET = digitalRead (buttonSET);
  if (buttonStateSET != oldButtonStateSET) {
    if (millis () - buttonPressTimeSET >= debounceTime) { // debounce
      buttonPressTimeSET = millis ();  // when we closed the switch
      oldButtonStateSET =  buttonStateSET;  // remember for next time
      if (buttonStateSET == LOW) {
        //Serial.println ("Button closedSET "); // DEBUGGING: print that button has been closed
        buttonPressedSET = 1;
      }
      else {
        // Serial.println ("Button opened"); // DEBUGGING: print that button has been opened
        buttonPressedSET = 0;
      }
    }  // end if debounce time up
  } // end of state change
}

//-----------------------------------------------------------
void Adjust() {
  BlauweLed(1, 1, 1, 1);// leds off
  buttonread();
  if (menu < 0) {
    menu = 0;
  }
  if (menu > 7) {
    menu = 7;
  }
  Serial.print("menu ");
  Serial.println(menu);

  switch (menu) {
    case 0 :
      DisplayAdjust();
      break;
    case 1:
      Displaykeuze1(32);
      if ( buttonPressedSET == 1) {
        buttonPressedSET = 0;
        AdjustUUR();
      }
      break;

    case 2:
      DisplaykeuzeWT(32);
      if (buttonPressedSET == 1) {
        buttonPressedSET = 0;
        AdjustWT();
      }
      break;

    case 3:
      Displaykeuze2(32);
      if (buttonPressedSET == 1) {
        buttonPressedSET = 0;
        AdjustMIN();
      }
      break;
    case 4:
      Displaykeuze4(32);
      if (buttonPressedSET == 1) {
        buttonPressedSET = 0;
        AdjustDAG();
      }
      break;

    case 5:
      Displaykeuze5(32);
      if (buttonPressedSET == 1) {
        buttonPressedSET = 0;
        AdjustMND();
      }
      break;

    case 6:
      Displaykeuze6(32);
      if (buttonPressedSET == 1) {
        buttonPressedSET = 0;
        AdjustYR();
      }
      break;
    case 7:
      AR = AgingRead();
      Displaykeuze8(AR, 104);
      if (buttonPressedSET == 1) {
        buttonPressedSET = 0;
        AdjustAging();
      }
      break;

  }
}
// ------------------------------------------------------
void DisplayAdjust() {
  DDP(190, 230, 198, 214, 124, 240);
}

//-------------------------------------------------------------
void AdjustUUR() {
  int exx = 0;
  menu = 1;
  Displaykeuze1(104);
  while (exx == 0) {
    buttonread();
    //Serial.println (menu);
    if (menu == 0) {
      Displaykeuze1(32);// uur
    }
    //-----------------
    // buttonread();

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

    }

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

    }
    if (buttonPressedSET == 1 & menu != 0) {
      zet_uur(hour);
      Displaykeuze1(72);// uur
      menu = 0;
      exx = 1;
    }

  }
}


// ------------------------------------------------------
void Displaykeuze1(int x) {
  DDP(196, 196, 160, x, LED1[f], LED1[e]);
}

//-------------------------------------------------------------
void AdjustWT() {
  int exx = 0;
  menu = 1;
  DisplaykeuzeWT(104);

  while (exx == 0) {
    buttonread();
    //Serial.println (menu);
    if (menu == 0) {
      DisplaykeuzeWT(32);
    }
    //-----------------
    buttonread();

    if ( menu > 1) {
      WT = 1;
      DisplaykeuzeWT(8);

      menu = 1;

    }

    // --------------------------
    if ( menu < -1) {
      WT = 0;
      DisplaykeuzeWT(64);

      menu = -1;

    }
    if (buttonPressedSET == 1 & menu != 0) {
      WT = 0;
      DisplaykeuzeWT(72);

      menu = 0;
      exx = 1;
    }

  }
}


// ------------------------------------------------------
void DisplaykeuzeWT(int x) {
  DDP(240, 240, 0, x, 0, LED1[WT]);
}

//-----------------------------------------------------------
void AdjustMIN() {
  int exx = 0;
  Displaykeuze2(104);

  menu = 1;
  while (exx == 0) {

    buttonread();
    //Serial.println (menu);
    if (menu == 0) {
      Displaykeuze2(32);// min
    }
    //-----------------
    //buttonread();

    if ( menu > 1) {
      minute = minute + 1;
      if (minute == 60) {
        minute = 0;
      }
      Factor (minute, false);
      c = EH;
      d = TT;
      Displaykeuze2(8);// min

      menu = 1;
    }

    // --------------------------
    if ( menu < -1) {
      minute = minute - 1;
      if (minute < 0) {
        minute = 59;
      }

      Factor (minute, false);
      c = EH;
      d = TT;
      Displaykeuze2(64);// min

      menu = -1;
    }
    if (buttonPressedSET == 1 && menu != 0) {
      zet_seconde(0);// set seconds
      zet_minuut(minute); // set minutes
      Displaykeuze2(72);// min

      menu = 0;
      exx = 1;
    }

  }
}


// ------------------------------------------------------
void Displaykeuze2(int x) {
  DDP(158, 6, 164, x, LED1[d], LED1[c]);
}


//----------------------------------------------------------
void AdjustDAG() {
  int exx = 0;
  Displaykeuze4(104);

  menu = 1;
  while (exx == 0) {
    buttonread();
    if (menu == 0) {
      Displaykeuze4(32);// min
    }
    //-----------------
    if ( menu > 1) {
      monthDay = monthDay + 1;
      if (monthDay == 32) {
        monthDay = 1;
      }
      Factor (monthDay , false);
      g = EH;
      h = TT;
      Displaykeuze4(8);// min

      menu = 1;
    }


    // --------------------------
    if ( menu < -1) {
      monthDay = monthDay - 1;
      if (monthDay == 0) {
        monthDay = 31;
      }
      Factor (monthDay , false);
      g = EH;
      h = TT;
      Displaykeuze4(64);// uur

      menu = -1;
    }
    if (buttonPressedSET == 1 && menu != 0) {
      zet_datum(monthDay);// set day of month
      Displaykeuze4(72);// min

      menu = 0;
      exx = 1;
    }
  }
}
// ------------------------------------------------------
void Displaykeuze4(int x) {
  DDP(230, 190, 118, x, LED1[h], LED1[g]);
}

//-------------------------------------------------------
void AdjustMND() {
  int exx = 0;
  Displaykeuze5(104);

  menu = 1;
  while (exx == 0) {
    buttonread();
    if (menu == 0) {
      Displaykeuze5(32);// min
    }
    //-----------------

    if ( menu > 1) {
      month = month + 1;
      if (month == 13) {
        month = 1;
      }
      Factor (month , false);
      i = EH;
      j = TT;
      Displaykeuze5(8);// min

      menu = 1;
    }

    // --------------------------
    if ( menu < -1) {
      month = month - 1;
      if (month == 0) {
        month = 12;
      }

      Factor (month , false);
      i = EH;
      j = TT;
      Displaykeuze5(64);// uur

      menu = -1;
    }
    if (buttonPressedSET == 1 && menu != 0) {
      zet_maand(month);// set month
      Displaykeuze5(72);// min

      menu = 0;
      exx = 1;
    }
  }
}
// ------------------------------------------------------
void Displaykeuze5(int x) {
  DDP(158, 164, 230, x, LED1[j], LED1[i]);
}

//------------------------------------------------------
void AdjustYR() {
  int exx = 0;
  Displaykeuze6(104);
  menu = 1;

  while (exx == 0) {

    buttonread();

    if (menu == 0) {
      Displaykeuze6(32);// min
    }
    //-----------------

    if ( menu > 1) {
      year = year + 1;
      if (year > 99) {
        year = 0;
      }
      Factor (year , false);
      k = EH;
      m = TT;
      Displaykeuze6(8);// min

      menu = 1;
    }

    // --------------------------
    if ( menu < -1) {
      year = year - 1;
      if (year < 0) {
        year = 99;
      }
      Factor (year , false);
      k = EH;
      m = TT;
      Displaykeuze6(64);// uur

      menu = -1;
    }
    if (buttonPressedSET == 1 && menu != 0) {

      zet_jaar(year);// set year
      Displaykeuze6(72);
      delay(300);
      menu = 0;
      exx = 1;
    }

  }
}
// ------------------------------------------------------
void Displaykeuze6(int x) {
  DDP(118, 160, 0, x, LED1[m], LED1[k]);
}
//------------------------------------------------------
void AdjustAging() {
  int exx = 0;
  menu = 1;
  AR = AgingRead();
  Displaykeuze8(AR, 72);

  while (exx == 0) {

    buttonread();
    if (menu == 0) {
      Displaykeuze8(AR, 104);
    }


    if (menu > 1) {
      AR = AR + 1;
      if (AR > 127) {
        AR = 0;
      }

      Displaykeuze8(AR, 8);
      menu = 1;
    }

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

      Displaykeuze8(AR, 64);
      menu = -1;
    }
    if (buttonPressedSET == 1 & menu != 0) {
      Agingadjust(AR);
      Displaykeuze8(AR, 190);
      menu = 0;
      exx = 1;
    }
  }
}
// ------------------------------------------------------
void Displaykeuze8(byte ARR, byte disp) {
  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(disp, 0, 0, LED1[HT], LED1[TT], LED1[EH]);
  }
  else
  {
    RR = RR - 256;
    RR = abs(RR);
    Factor(RR, false);
    DDP(disp, 0, 32, LED1[HT], LED1[TT], LED1[EH]);
  }

}
//-------------------------------------------------------------
void NormalMode() {
  digitalWrite(clockPin1, 0);
  digitalWrite(OutEnable, 1);
  digitalWrite(latchPin1, 0);
  digitalWrite(clockPin1, 1);
  //----------------------
  digitalWrite(clockPin1, 0);
  digitalWrite(OutEnable, 0);
  digitalWrite(latchPin1, 0);
  digitalWrite(clockPin1, 1);
  //----------------------
  digitalWrite(clockPin1, 0);
  digitalWrite(OutEnable, 1);
  digitalWrite(latchPin1, 0);
  digitalWrite(clockPin1, 1);
  //----------------------
  digitalWrite(clockPin1, 0);
  digitalWrite(OutEnable, 1);
  digitalWrite(latchPin1, 0);
  digitalWrite(clockPin1, 1);
  //----------------------
  digitalWrite(clockPin1, 0);
  digitalWrite(OutEnable, 1);
  digitalWrite(latchPin1, 0);
  digitalWrite(clockPin1, 1);
  //-------------------------
  digitalWrite(clockPin1, 0);

}
//-------------------------------------------------------------
void Tijd() {
  BlauweLed(0, 0, 0, 0);// zero is on, 1 is off
  DDP(LED1[f], LED1[e], LED1[d], LED1[c], LED1[b], LED1[a]);
}
//-------------------------------------------------------------
void TijdDig() {
  BlauweLed(0, 0, 0, 0);
  DDP(LDIG[f], LDIG[e], LDIG[d], LDIG[c], LDIG[b], LDIG[a]);

}
//-------------------------------------------------------------
void TijdZS() {
  BlauweLed(1, 1, 1, 1);
  byte testsec = second;
  testsec %= 2;
  if (testsec == 0) {
    DDP(LED1[f], LED1[e], 8, 64, LED1[d], LED1[c]);
  }
  else
  {
    DDP(LED1[f], LED1[e], 64, 8, LED1[d], LED1[c]);
  }
}

//------------------------------------------------------------------
// MSB out first!
void ssrWriteMSB(byte value)   {
  for (int x = 0; x < 8; x++)   {
    byte temp = value & 0x80;
    if (temp == 0x80)   digitalWrite(dataPin1, 1); // data bit HIGH
    else digitalWrite(dataPin1, 0); // data bit LOW
    pulseCLK();
    value = value << 0x01; // shift left
  }
}
//----------------------------------------------

void pulseCLK()
{
  digitalWrite(clockPin1, 1);
  digitalWrite(clockPin1, 0);
}
//-------------------------------------------------------------
void Datum () {
  BlauweLed(1, 0, 1, 0);
  DDP(LED1[h], LED1[g], LED1[j], LED1[i], LED1[m], LED1[k]);

}
//---------------------------------------------------------
void Ledtest () {
  int x;

  for (x = 0; x < 10; x++) {
    DDP(LED1[x], LED1[x], LED1[x], LED1[x], LED1[x], LED1[x]);
    delay(500);
  }
  delay(1000);
}
//-------------------------------------------
void LuchtDruk() {

  BlauweLed(1, 1, 1, 1);
  Factor (P / 100 , false);

  DDP(LED1[DT], LED1[HT], LED1[TT], LED1[EH], LED2[0], LED2[1]);

}

//-------------------------------------------------------------
void LCDTemp() {

  BlauweLed(1, 1, 1, 0);
  Factor (T * 10 , false);
  DDP(LED1[HT], LED1[TT], LED1[EH], LED2[2], LED2[3], LED2[4]);

}

//--------------------------------------------------------
void NachtMode() {

  if (hour >= 0 & hour < 8) {
    DDP(LDIG[0], LDIG[0], LDIG[0], LDIG[0], LDIG[0], LDIG[0]);
    BlauweLed(1, 1, 1, 1);
  }
  else
  {
    digitalWrite(OutEnable, 1);
    BlauweLed(0, 0, 0, 0);
    Tijd();
  }


}

// --------------------------------------------------------------
void DagNR() {
  int DR;
  BlauweLed(1, 1, 1, 1);
  Schrikkeljaar ();
  DR = TotaalDagen(month) +  monthDay;

  Factor (DR , false);

  DDP(LED2[6], LED2[7], LED2[8], LED1[HT], LED1[TT], LED1[EH]);

}
// -------------------------------------------------------------------
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() {
  long DS;
  long uur;
  BlauweLed(1, 1, 1, 1);
  uur = hour;
  DS = (uur * 3600);
  DS += (minute * 60);
  DS += second;

  Factor (DS , false);

  DDP(LED2[2], LED1[TDT], LED1[DT], LED1[HT], LED1[TT], LED1[EH]);


}
//------------------------------------------------------
void MinutenJaar() {
  long DS;
  long uur;
  BlauweLed(1, 1, 1, 1);
  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[HDT], LED1[TDT], LED1[DT], LED1[HT], LED1[TT], LED1[EH]);

}
//-----------------------------------------------------------------
void LEDMaan() {
  float Uur1;
  float Min1;
  float MOud;
  int Index;
  float AZ;
  float test11;
  BlauweLed(1, 0, 1, 1);
  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(LED2[9], LED2[9], LED1[DT], LED1[HT], LED1[TT], LED1[EH]);

}
// -----------------------------------------------------
float LengtegraadCorrectie(float LLG) {
  float Lg1;
  Lg1 = LLG;


  if (LLG < 0) {
    while (Lg1 <= -15)
    {
      Lg1 += 15;
    }
    Lg1 = abs(Lg1);
  }


  if (LLG >= 0) {
    while (Lg1 >= 15)
    {
      Lg1 -= 15;
    }
    Lg1 = 15 - Lg1;
  }

  return ( Lg1 / 15);
}

//---------------------------------------------------------
void Zonsopgang() {
  float AZ;
  float Decc;
  float ZZ;
  float TVE;
  float LG1;
  BlauweLed(0, 0, 1, 1);
  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  AZ = AZ - Lentepunt + monthDay;
  Decc = Declinatie(AZ, Dagen);
  ZonOpOnder(Decc, BG);// aanroepen routine
  LG1 = LengtegraadCorrectie (LG);
  ZZ = ZonOp + LG1; //0.683333;
  ZZ += WT;
  AZ += Lentepunt;

  TVE = Tijdvereffening(AZ, Dagen);

  ZZ += TVE;

  Factor (ZZ * 100 , true);

  DDP(LED2[9], LED2[2], LED1[DT], LED1[HT], LED1[TT], LED1[EH]);
}
//---------------------------------------------------------
void Zonsondergang() {
  float BB;
  float AZ;
  float Decc;
  float ZZ;
  float TVE;
  float LG1;
  BlauweLed(0, 0, 1, 1);
  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  AZ = AZ - Lentepunt + monthDay ;
  Decc = Declinatie(AZ, Dagen);
  ZonOpOnder(Decc, BG);// aanroepen routine
  LG1 = LengtegraadCorrectie (LG);
  ZZ = ZonOnder + LG1; //0.683333;
  ZZ += WT;
  AZ += Lentepunt;

  TVE = Tijdvereffening(AZ, Dagen);

  ZZ += TVE;

  Factor (ZZ * 100 , true);

  DDP(LED2[9], LED2[2], LED1[DT], LED1[HT], LED1[TT], LED1[EH]);

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

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 Tijd1;
  float AZ;
  float Decc;
  float TVE;
  float Tijd2;
  float HGTE;
  float Hoogte;
  float LG1;
  float ZZ;
  BlauweLed(0, 0, 1, 1);
  Tijd1 = hour + (minute / 60.0);
  Tijd1 = Tijd1 + (second / 3600.0);
  LG1 = LengtegraadCorrectie (LG);
  Tijd1 = Tijd1 - WT - LG1; //0.683333;
  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);

  ZZ = Hoogte;
  ZZ = abs(ZZ);// fabs = absoluut
  Serial.print("hoogte: ");
  Serial.println(ZZ);
  Factor (ZZ * 100 , true);
  if (Hoogte >= 0) {
    DDP(0, 0, LED1[DT], LED1[HT], LED1[TT], LED1[EH]);
  }
  else
  {
    DDP(0, 32, LED1[DT], LED1[HT], LED1[TT], LED1[EH]);
  }

}

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


  Factor (BB2 , true);
  if (BB >= 0) {
    DDP(0, 0, LED1[DT], LED1[HT], LED1[TT], LED1[EH]);
  }
  else
  {
    DDP(0, 32, LED1[DT], LED1[HT], LED1[TT], LED1[EH]);
  }

}
//-----------------------------------------------
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() {
  float BB;
  float AZ;
  float Decc;
  BlauweLed(0, 0, 1, 1);
  Schrikkeljaar ();
  AZ = TotaalDagen(month);
  //AZ = 180;
  AZ = (AZ - Lentepunt) + monthDay ;
  Decc = Declinatie(AZ, Dagen);
  BB = Hoogte(Decc, BG);

  Factor (BB * 100 , true);

  DDP(90, LED2[2], LED1[DT], LED1[HT], LED1[TT], LED1[EH]);


}
//--------------------------------------------------------------------------
void BlauweLed(byte D1, byte D2, byte D3, byte D4) {
  digitalWrite(LedRB, D1);
  digitalWrite(LedRO, D2);
  digitalWrite(LedLB, D3);
  digitalWrite(LedLO, D4);
}

Credits

jg53fn55

jg53fn55

0 projects • 4 followers
I am retired.

Comments