Question about 6b595 with real time clock

Hello

I don't know if this is programming question or hardware but I'm 99% sure that is a programming question that is why i'm post it here.

So my problem is that program works of some time and after around 12 hours Arduino is kind a stops looping and it block.

Every 6B595 are connected to one 7 segment LED display to control it.

I'm attaching my scheme too.

Here is the code:

#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <TimeLib.h>
#include <Wire.h>
#include <DallasTemperature.h>
#include <EEPROM.h>
#include <OneWire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <DS1307RTC.h>
#include "lastSunday.h"

const int clockPin              = 13;
const int latchPin              = 10;
const int dataPin               = 12;

//temp object - sensors
#define ONE_WIRE_BUS 2  //temperature pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

//DHT11 sensor
#define DHTPIN            3         // Pin which is connected to the DHT sensor.
#define DHTTYPE           DHT11     // DHT 11 
DHT_Unified dht(DHTPIN, DHTTYPE);

//gps object - gps
TinyGPS gps;
//gps data object
SoftwareSerial dataObj(5, 4);

int correctTime();

//creating lastSunday object which find the last sunday of every month
lastSunday ls;

//Water temperature value
int WaterTemp;
int TempDigit = 0;

int minuteDigit; 
int hourDigit;
int dateDigit; 
int monthDigit;

int i=0;
int prevtemp;
int temp;
int dhttemp;
int dhthum;

//timer turning on/off dots between numbers of the clock
unsigned long prevTimeDots = 0;
boolean turnD = true;

//Parameters for display digits
int splitSecondDigit1, splitSecondDigit2;
int splitMinuteDigit1, splitMinuteDigit2;
int splitHourDigit1, splitHourDigit2;

int splitMonthDigit1, splitMonthDigit2;
int splitDateDigit1, splitDateDigit2;

int splitTemp1, splitTemp2;

int splitWaterTempDigit1, splitWaterTempDigit2;

int splitDHTTemp1, splitDHTTemp2;
int splitDHTHum1, splitDHTHum2;
  
byte firstSecondDigit, secondSecondDigit;
byte firstMinuteDigit, secondMinuteDigit;
byte firstHourDigit, secondHourDigit;

byte firstDateDigit, secondDateDigit;
byte firstMonthDigit, secondMonthDigit;

byte firstTempDigit, secondTempDigit,thirdTempDigit;

byte firstWaterTempDigit, secondWaterTempDigit;

byte firstDHTTempDigit, secondDHTTempDigit;
byte firstDHTHumDigit, secondDHTHumDigit;

//led digits
//0,1,2,3,4...,9
byte IC1[] = {
  B11111100,
  B01100000,
  B11011010,
  B11110010,
  B01100110,
  B10110110,
  B10111110,
  B11100000,
  B11111110,
  B11110110
};

void displayAll(); // Display Time



void setup() {
  Serial.begin(115200);
  dataObj.begin(9600);
  setSyncProvider(RTC.get);
  RTC.set(now());
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  digitalWrite(ButtonUpPin,HIGH);
  digitalWrite(ButtonEnterPin,HIGH);
  digitalWrite(ButtonDownPin,HIGH);

  WaterTemp = EEPROM.read(0);
  if (WaterTemp < 15 && WaterTemp > 50) {
    WaterTemp = 30;
  }

  sensors.begin();
  
  dht.begin();

  TestDisplay();
  
  
}

void loop() {
  
  if (dataObj.available()) {  //if gps recieve data
    while (dataObj.available()) { //while it is recieving
      if (gps.encode(dataObj.read())) { //gps.encode if data is valid 
        int yearMy;
        byte monthMy, dayMy, hourMy, minuteMy, secondMy, hundredthsMy;
        unsigned long ageMy;
        //take gps data
        gps.crack_datetime(&yearMy, &monthMy, &dayMy, &hourMy, &minuteMy, &secondMy, &hundredthsMy, &ageMy);
        //data validation
        if ((hourMy >= 0) && (minuteMy >= 0)) {
          //seting Real Time Clock time according to gps time
          //correcting gps UTC time according to BG time
          //look at correctTime() function
          setTime(hourMy + correctTime(), minuteMy, secondMy, dayMy, monthMy, yearMy);
          RTC.set(now());
        }
      }
    }
    displayAll();
    }

  else displayAll();  //if no gps available display Real Time Clock time
    
  delay(1000);
}            

//Test all display with 8 beside minus symbol
void TestDisplay() {
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, B00000010);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
 
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);

  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);

  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);

  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  digitalWrite(latchPin, HIGH);
  digitalWrite(latchPin, LOW);

  delay(1000);

  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, LSBFIRST, B00000010);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
 
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);

  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);

  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);

  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  shiftOut(dataPin, clockPin, LSBFIRST, B11111111);
  digitalWrite(latchPin, HIGH);
  digitalWrite(latchPin, LOW);

  delay(500);

  
}

This is the additional code:

//Function that displays Hour
void displayAll() {

  minuteDigit = minute(); 
  hourDigit   = hour();
  
  dateDigit = day(); 
  monthDigit   = month();

  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);

  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  dhttemp = event.temperature;
  dht.humidity().getEvent(&event);
  dhthum = event.relative_humidity;

  Serial.print("Ok, Time = ");
  Serial.print(hourDigit);
  Serial.write(':');
  Serial.print(minuteDigit);
  Serial.print(", Date (D/M) = ");
  Serial.print(dateDigit);
  Serial.write('/');
  Serial.print(monthDigit);
  Serial.write(", Temperature 1: ");
  Serial.print(temp);
  Serial.write(", Temperature 2: ");
  Serial.print(dhttemp);
  Serial.write(", Humidity: ");
  Serial.print(dhthum);

  Serial.println();

  splitHourDigit1 = hourDigit / 10; //taking first digit of the number
  splitHourDigit2 = hourDigit % 10; //taking second digit of the number

  splitMinuteDigit1 = minuteDigit / 10; //taking first digit of the number  
  splitMinuteDigit2 = minuteDigit % 10; //taking second digit of the number

  //finding the correct number in IC1 table 
  firstMinuteDigit = IC1[splitMinuteDigit1];
  secondMinuteDigit = IC1[splitMinuteDigit2];

  firstHourDigit = IC1[splitHourDigit1];
  secondHourDigit = IC1[splitHourDigit2];

  splitMonthDigit1 = monthDigit / 10; //taking first digit of the number
  splitMonthDigit2 = monthDigit % 10; //taking second digit of the number

  splitDateDigit1 = dateDigit / 10; //taking first digit of the number  
  splitDateDigit2 = dateDigit % 10; //taking second digit of the number

  firstDateDigit = IC1[splitDateDigit1];
  secondDateDigit = IC1[splitDateDigit2];

  firstMonthDigit = IC1[splitMonthDigit1];
  secondMonthDigit = IC1[splitMonthDigit2];

  splitWaterTempDigit1 = WaterTemp / 10; //taking first digit of the number  
  splitWaterTempDigit2 = WaterTemp % 10; //taking second digit of the number

  //finding the correct number in IC1 table
  firstWaterTempDigit = IC1[splitWaterTempDigit1];
  secondWaterTempDigit = IC1[splitWaterTempDigit2];
  
  if (temp != prevtemp)
  {
  if (temp < 0) { // if temperature is negative
    temp = abs(temp);
    splitTemp1 = temp / 10; //taking first digit of the number
    splitTemp2 = temp % 10; //taking second digit of the number
    //finding the correct number in IC1 table 
    firstTempDigit  = IC1[splitTemp1];
    secondTempDigit = IC1[splitTemp2];
    thirdTempDigit = B00000010;
    prevtemp = temp;
  } 
  else if ( temp == 0) { // if temp is 0
    secondTempDigit = B11111100;
    firstTempDigit = B00000000;
    thirdTempDigit = B00000000;
    prevtemp = temp;
    }
    else { // if temp is positive
      splitTemp1 = temp / 10;
      splitTemp2 = temp % 10;
      firstTempDigit  = IC1[splitTemp1];
      secondTempDigit = IC1[splitTemp2];
      thirdTempDigit = B00000000;
      prevtemp = temp;
    }
  }

  splitDHTTemp1 = dhttemp / 10;
  splitDHTTemp2 = dhttemp % 10;
  firstDHTTempDigit  = IC1[splitDHTTemp1];
  secondDHTTempDigit = IC1[splitDHTTemp2];

  splitDHTHum1 = dhthum / 10;
  splitDHTHum2 = dhthum % 10;
  firstDHTHumDigit  = IC1[splitDHTHum1];
  secondDHTHumDigit = IC1[splitDHTHum2];
  
  digitalWrite(latchPin, LOW); 

  shiftOut(dataPin, clockPin, LSBFIRST, thirdTempDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, firstTempDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, secondTempDigit);

  shiftOut(dataPin, clockPin, LSBFIRST, firstWaterTempDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, secondWaterTempDigit);

  shiftOut(dataPin, clockPin, LSBFIRST, firstDHTTempDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, secondDHTTempDigit);

  shiftOut(dataPin, clockPin, LSBFIRST, firstDHTHumDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, secondDHTHumDigit);

  shiftOut(dataPin, clockPin, LSBFIRST, secondMonthDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, firstMonthDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, secondDateDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, firstDateDigit);

  shiftOut(dataPin, clockPin, LSBFIRST, secondMinuteDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, firstMinuteDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, secondHourDigit);
  shiftOut(dataPin, clockPin, LSBFIRST, firstHourDigit);
  
  digitalWrite(latchPin, HIGH);
  digitalWrite(latchPin, LOW);
}

//correcting UTF time which comes from gps
//making it Bulgarian time
int correctTime() {
  int yearMy, monthMy, dayMy, lastSunMar, lastSunOct;
  yearMy  = year();
  //find every last sunday of each month of selected year (yearMy)
  ls.findLastSunday(yearMy);
  
  //getting the last sunday of selected month
  //months start from 0
  lastSunMar = ls.getDay(2);
  lastSunOct = ls.getDay(9);
  //

  //hour and month from RTC
  dayMy   = day();
  monthMy = month();
  //

  //checking what month and day it is and determining whether to add +2 or +3 to UTC time 
  bool state1 = ((monthMy == 10) && (dayMy >= lastSunOct));
  bool state2 = ((monthMy > 10) || (monthMy <= 2));
  bool state3 = ((monthMy == 3) && (dayMy < lastSunMar));

  if (state1 || (state2 || state3)){
    return 2;
  } else {
    return 3;
  }
}
int splitSecondDigit1, splitSecondDigit2;
int splitMinuteDigit1, splitMinuteDigit2;
int splitHourDigit1, splitHourDigit2;

int splitMonthDigit1, splitMonthDigit2;
int splitDateDigit1, splitDateDigit2;

What range of values are you storing in these variables? Do they NEED to be ints? Or would some smaller type be more appropriate?

Why do these all need to be global in scope?

  if (WaterTemp < 15 && WaterTemp > 50) {
    WaterTemp = 30;
  }

What value of WaterTemp can be less than 15 and greater than 50 at the same time?

      if (gps.encode(dataObj.read())) { //gps.encode if data is valid

No. The gps.encode() function is poorly named. It stores the character in the buffer, and returns true if that character completes a sentence. The comments are pretty much useless.

// Comments that start in column 1, and explain what a block of code is trying to do are
// far more useful than end of the statement comments.

  if (dataObj.available()) {  //if gps recieve data
    displayAll();
    }

  else displayAll();  //if no gps available display Real Time Clock time

Putting every { on a line BY ITSELF and using Tools + Auto Format would be helpful for understanding what blocks of code look like, since the { and the } then line up. What this stuff is saying is that if there is serial data, deal with it and call displayAll(). Otherwise, just call displayAll().

It makes no sense to conditionally call a function when you then call it in the else clause, too.

Get the call out of the if block and do away with the else statement.

  minuteDigit = minute();

The name IMPLIES that you expect the function to return a one digit value. It does NOT always do that. A better name is definitely in order. That variable should be local to the function, since no other function cares about the value.

Arduino is kind a stops looping and it block.

You're going to need to add Serial.print() statements to find out where is appears to stop.

It would be better to have some functions that get the date/time data, that get the temperature data, etc. so you can test a function, and then forget it.

Thank you for the comment.
Yes the values you mentioned should be in byte.
I use it global scope because i change the code a few time and in one point i need values in global so just left them there. I don't thing that is the problem. Yes it's poorly written.

About WaterTemp I change it it should be "OR" not "AND".

How gps.encode() function should be named?

About the comment sorry i will fix it.

I will fix the names too.

I try with Serial.print but i could not find the mistake that why i'm asking here.

But in general i don't think any of this should stop arduino to work. I will fix all of yours comments and i will try.

How gps.encode() function should be named?

You shouldn't change the name, since you don't own the library. But, the author should have named the function append(), since what it does is append the character to the end of the string it is building.