The program crashes

I'm sorry I'm new here, and I need help.
why is my program interrupted?
and how should I solve this?`
to facilitate review, the program is not complete,
but the rest works

#include <DS3232RTC.h>
#include <Time.h>
#include <LCD5110_Graph.h>
LCD5110 myGLCD(13,11,9,7,8);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];


int preklop=0;
 tmElements_t tm;
 int uraa[]={0, 0, 0, 0, 0, 0, 0, 0}; //[0]alarem ure 1, [1] alarem minute 1, [2]alarem ure 2, [3]alarem minute 2, 
const byte rtcAlarmPin = 8;//pin read by polling, could be set up an an external interrupt on pin2/3
byte Hour[6];



void setup()
{
// Serial.begin(9600); 
 myGLCD.InitLCD();
//nastavitelefonsko();

myGLCD.clrScr();
RTC.read(tm);

if(digitalRead (12) == HIGH) {
nastaviuro();
}
}

void loop() {


 }
void nastaviuro() { 

 myGLCD.setFont(SmallFont);

  tmElements_t tm;

if( preklop==0 ){// nastavi uro
 
  odsteva();
  delay(1000);

  tmElements_t tm;
 RTC.read(tm);

 Hour[0]=tm.Hour;
 Hour[1]=tm.Minute;
 Hour[2]=tm.Second;
  Hour[3]=tm.Day;
   Hour[4]=tm.Month;
    tm.Year=tm.Year-96;
   Hour[3]=tm.Year;

 preklop=1;
 }

if(digitalRead (12) == HIGH) {
      preklop=preklop+1;
      delay(800);
    }// tipka preklop


if(preklop==1){   // nastavi uro
//  display.setCursor(63,0);
   myGLCD.print("ura",15,0);;
if(digitalRead (10) == HIGH)  //
{
    Hour[0]=( Hour[0]+1);
if( Hour[0] >= 25)  // 
{
  Hour[0]=1;
myGLCD.printNumI( Hour[0],0,0);
}

 }  
 myGLCD.printNumI(Hour[0],0,0);
}
// //*************************************************************************
 if(preklop==2){   // nastavi minute
   myGLCD.print("min",15,10);
    if(digitalRead (10) == HIGH)  //
{
  Hour[1]=Hour[1]+1;
   if(Hour[1] >= 60)  // 
{
  Hour[1]=0; 
}
 }  
 myGLCD.printNumI(Hour[1],0,10); 
}

// //************************************************************************
 if(preklop==3){   // nastavi minute
   myGLCD.print("sec",15,20);
    if(digitalRead (10) == HIGH)  //
{
  Hour[2]=Hour[2]+1;
   if(Hour[2] >= 60)  // 
{
  Hour[2]=0; 
}
 }  
 myGLCD.printNumI(Hour[2],0,20); 
}
if(preklop==4){
  myGLCD.clrScr();
 preklop=5; 
}

// //************************************************************************
 if(preklop==5){   // nastavi minute
   myGLCD.print("dan",15,0);
    if(digitalRead (10) == HIGH)  //
{
  Hour[3]=Hour[3]+1;
   if(Hour[3] >= 32)  // 
{
  Hour[3]=0; 
}
 }  
 myGLCD.printNumI(Hour[3],0,0); 
}
// //************************************************************************
 if(preklop==6){   // nastavi minute
   myGLCD.print("mesec",15,10);
    if(digitalRead (10) == HIGH)  //
{
  Hour[4]=Hour[4]+1;
   if(Hour[4] >= 13)  // 
{
  Hour[4]=0; 
}
 }  
 myGLCD.printNumI(Hour[4],0,10); 
}
// //************************************************************************
 if(preklop==7){   // nastavi minute
   myGLCD.print("leto",15,20);
    if(digitalRead (10) == HIGH)  //
{
  Hour[5]=Hour[5]+1;
   if(Hour[5] >= 99)  // 
{
  Hour[5]=0; 
}
 }  
 myGLCD.printNumI(Hour[5],0,20); 
}

if(preklop==7){ 
  
 static time_t tLast;
    time_t t;

      tm.Year = Hour[5];
      tm.Month = Hour[4];
            tm.Day = Hour[3];
            tm.Hour = Hour[0];
            tm.Minute = Hour[1];
            tm.Second = Hour[2];
            t = makeTime(tm);

            RTC.set(t);        //use the time_t value to ensure correct weekday is set
            setTime(t); 
            delay(500);

//            display.print("nastavljeno");
//            nastavialarem();
//           display.clearDisplay();

  
}
 //************************************************************************

delay(400);
myGLCD.update();
nastaviuro();
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
 void odsteva() {

  myGLCD.print("2",0,0);
 myGLCD.update();

  delay(1000);

  myGLCD.print("1",0,0);
  myGLCD.update();

  delay(1000);

  myGLCD.print("0",0,0);
myGLCD.update();

}

What exactly happens when you run the sketch ?

Hour[3]=tm.Day;
. . .
   Hour[3]=tm.Year;

?

(To facilitate getting more code, this answer is not complete)

Hour[3]=tm.Day;
. . .
   Hour[3]=tm.Year;

ok it's a minor mistake.
the program runs for a while, then restarts

Is that code complete and runnable?

That can be a symptom of writing or reading beyond the bounds of an array. Examine all array operations for boundary violations.

it’s not complete, but you can runnable
works if in void loop();
when I move it to nastaviuro (); blocks


#include <EEPROM.h>
#include "DHT.h"
//#include <Adafruit_Sensor.h> 
#include <DS3232RTC.h>
#include <Time.h>
#include <SoftwareSerial.h>

#include "HX711.h"
 HX711 scale(3, 2); 
//byte scale[]={3, 2, 128};
//float kgkk=0.0;
float kgkk;
float kgk1[3];// 0 bere iz senzora in deli, 1 prva vrednost shranjena v eeprom
long kgint[5];






#include <LCD5110_Graph_krajse.h>
//#include <LCD5110_Graph.h>
LCD5110 myGLCD(13,11,9,7,8);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];

long previousMillist = 0;       
long intervalt = 300;
#define DHTPIN1 A0   
#define DHTTYPE1 DHT11   // DHT 11
 DHT dht1(DHTPIN1, DHTTYPE1);
int tempvlaga[]={0, 0, 0, 0, 0}; //[0]tempe 1, [1] vlaga 1, [2]temp 2, [3]vlaga 2

 
SoftwareSerial sim(6, 5);
char m1[140]="";
int tel[13]={};
char tele[13]="";
   int signa[2];
int ttt[]={0, 0, 0, 0};
   int tt=0;


int uraa[]={0, 0, 0, 0, 0, 0, 0, 0}; //[0]alarem ure 1, [1] alarem minute 1, [2]alarem ure 2, [3]alarem minute 2, 
const byte rtcAlarmPin = A2;//pin read by polling, could be set up an an external interrupt on pin2/3
int preklop=-1;
byte Hour[6];

void setup()
{
  Serial.begin(9600);
  myGLCD.InitLCD();
sim.begin(4800);
 dht1.begin();
//  kgkk = beri();

 RTC.alarmInterrupt(1,1);//enable alarm 1 interrupt A1IE
  RTC.alarmInterrupt(2,1);//enable alarm 2 interrupt A2IE
  RTC.squareWave(SQWAVE_NONE);
  uraa[0]= EEPROM.read(40);
  uraa[1]= EEPROM.read(42);
  uraa[2]= EEPROM.read(44);
  uraa[3]= EEPROM.read(46);
  delay(500); 
  RTC.setAlarm(ALM2_MATCH_HOURS,0,uraa[3],uraa[2],0);
  RTC.setAlarm(ALM1_MATCH_HOURS,0,uraa[1],uraa[0],0);


  
//delay(2000);



  // AVTOMATSKO NIČLIRANJE
  if(digitalRead (10) == HIGH)  // 0,1=1 2,3=2 4,5=3 6,7=4 8,9=5 10,11=6 12,13=7 14,15=8 16,17=9 18,19=10
{ if(digitalRead (12) == HIGH)  
{
//  nastavitelefonsko();
  }
 myGLCD.setFont(SmallFont); 
 myGLCD.print("avto nicliranje",0,0); 
 myGLCD.update();
int var = 0;
while(var < 10){
   beri();
   var++;
} 
EEPROMWriteInt(20, kgint[1]);
 delay(3500);
}

if(digitalRead (12) == HIGH)  
{
//  nastavitelefonsko();
  if(digitalRead (10) == HIGH)  
{
//  nastavitelefonsko();
  }
nastaviuro();
  }
//display.clearDisplay();
//nastavitelefonsko();
tmElements_t tm;
RTC.read(tm);

//nastaviuro();
  
}

void loop()
{
  
if (preklop==-1)
{
  if(digitalRead (12) == HIGH)  
{
  nastaviuro();
} 
  }
preklop=0;


  
  tmElements_t tm;
 RTC.read(tm);
  myGLCD.setFont(SmallFont);
  myGLCD.clrScr();
 int urp=0;
 int mip=0;
 if (tm.Hour>10){urp=7;}
if (tm.Minute>10){mip=7;}
  myGLCD.printNumI(tm.Hour, 0, 0);
 myGLCD.print(":", 7+urp, 0);

  myGLCD.printNumI(tm.Minute, 14+urp, 0);
  myGLCD.print(":", 21+urp+mip, 0);
  myGLCD.printNumI(tm.Second, 28+urp+mip, 0);

nic();




 float h = dht1.readHumidity();
  float t = dht1.readTemperature();
  float f = dht1.readTemperature(true);
  float hif = dht1.computeHeatIndex(f, h);
  float hic = dht1.computeHeatIndex(t, h, false);
 myGLCD.printNumI((int)t-3,0,32);//2
  tempvlaga[0]=t-3;//2
  myGLCD.print("~C ",18,32); 
 myGLCD.printNumI((int)h,0,40);//10
  tempvlaga[1]=h+20;//10
 myGLCD.print("%",18,40);


myGLCD.update();
}



//****************************************************************

 void EEPROMWriteInt(int p_address, int p_value)
{
 int a = p_value/255;
 int b = p_value % 255;
 EEPROM.write(p_address,a);
 EEPROM.write(p_address + 1,b);
}// konec zanke zapisovanje v eeprom

//***********************************************

//This function will read a 2 byte integer from the eeprom at the specified address and address + 1
 unsigned int EEPROMReadInt(int p_address)
{
 int a=EEPROM.read(p_address);
 int b=EEPROM.read(p_address + 1);
 return a*255+b;
      }// konec zanke branje iz eeproma
      
  //****************************************************************************************    

    void nic(){
kgkk = beri();

if (digitalRead (10) == HIGH) {

 kgint[4] = (EEPROMReadInt(0));
 if ( kgint[4] == 0) {
 unsigned long currentMillist = millis();
 if(currentMillist - previousMillist > intervalt) {
 previousMillist = currentMillist;  
 EEPROMWriteInt(0,  kgkk);

} 
}
 if ( kgint[4] != 0) {
 unsigned long currentMillist = millis();
 if(currentMillist - previousMillist > intervalt) {
 previousMillist = currentMillist;
 EEPROMWriteInt(0, 0);
} 
}
delay(500);
}

myGLCD.setFont(MediumNumbers);
if (EEPROMReadInt(0) > 0)
{
 kgint[4] = (EEPROMReadInt(0));
kgkk = kgkk-(kgint[4]);
kgkk=kgkk/10;
 myGLCD.printNumF(kgkk, 1, 0, 12, '.');  
  myGLCD.setFont(SmallFont);
myGLCD.print("kgk--", 66, 20);
}
else 
{
//kgkk=kgk1[3];
kgkk=kgkk/10;
myGLCD.setFont(MediumNumbers);
myGLCD.printNumF(kgkk, 1, 0, 12, '.');  
  myGLCD.setFont(SmallFont);
myGLCD.print("kg", 66, 20);
}
}
//________________________________________________________________
  float  beri(){ 

   kgint[0] =(EEPROMReadInt(20));
  kgk1[0]=scale.read_average(10)/10000;
kgk1[2]=((kgk1[0])*2.17);

 kgint[1]=kgk1[2];
 kgk1[3]=kgint[1]-kgint[0];

//myGLCD.setFont(MediumNumbers);
//myGLCD.printNumF(kgk1[3]/10, 1, 16,32, '.');
return kgk1[3];
  }
//______________________________________________________________

 void sms()
{
//   lcd.noBacklight();
{
sprintf(tele,"+%i%i%i%i%i%i%i%i%i%i%i",EEPROM.read(50),EEPROM.read(51),EEPROM.read(52),EEPROM.read(53),EEPROM.read(54),EEPROM.read(55),EEPROM.read(56),EEPROM.read(57),EEPROM.read(58),EEPROM.read(59),EEPROM.read(60));  //i+1 če želiš da se prvi panj začne z 1 in ne z 0
}



uraa[0]= EEPROM.read(40);
uraa[1]= EEPROM.read(42);
tmElements_t tm;
RTC.read(tm);

float kgz = (EEPROMReadInt(5));
int temp1z= (EEPROMReadInt(7));
int vlag1z= (EEPROMReadInt(9));
float kt1 = (EEPROMReadInt(0));


float b[10]={0.0};     
int unites;
int dixiemes; 

float bz[10]={0.0};     
int unitesz;
int dixiemesz;

float volt[10]={0.0};     
int unitesv;
int dixiemesv;
int sensorValue = analogRead(A1);
float voltage = sensorValue * (5.0 / 1023.0);

float don[10]={0.0};
int donosa;
int unitedon;
int dixiemedon; 

float tara[1]={0.0};     
int unitestara;
int dixiemestara;

    b[0]=random(0,50000);
    bz[0]=random(0,50000);

      beri();
      b[0]=kgk1[3];
 b[0]=b[0]/10;
//Serial.println(b[0]);
      
      tara[1]=(kgkk);
      
      b[0]=b[0];
      bz[0]=kgz/10;
      volt[0]=voltage;
      
//      Serial.println(kgz);
// Serial.println(kgkk);

  float kgzz=kgz/10;
//   Serial.println(kgzz);
  
  float dondon=b[0]-kgzz;  
  int dondon1=abs(dondon);
//  float  donsi=(int)dondon1;
   float  donsi=(int)dondon;
  donsi=donsi/10;
// don[0]=donsi;
 don[0]=dondon;
// unitedon=abs(don[0]);         
// dixiemedon=abs((abs(don[0]*10)-unitedon*10));
   
   
//   Serial.println(dondon);
//   Serial.println(donsi);
   
   
      unites=abs(b[0]);         
      dixiemes=abs((b[0]-unites)*10);
      
      unitesz=abs(bz[0]);         
      dixiemesz=abs((bz[0]-unitesz)*10);
      
      unitesv=abs(volt[0]);         
      dixiemesv=abs((volt[0]*10-unitesv*10));
            
      if (kt1==0)
      {
       tara[1]=0; 

        }


//tara[1]=-10.3;
//don[0]=-5.3;

byte precision = 1;

char donosbuff[20];
dtostrf(don[0], precision+3, precision, donosbuff);

char tarabuff[20];
dtostrf(tara[1], precision+3, precision, tarabuff);

sprintf(m1,"SMS cebelar\n Ob %i:%i\nteza %i.%ikg\nzraka:\nTemp:%iC\nVlag:%i%%\n************\n Ob %i:%i\nteza %i.%ikg\nzraka\nTemp:%iC\nVlag:%i%%\n************\n donos:%s kg\n tara:%s kg\n baterija %i.%iV",uraa[0],uraa[1],unitesz,dixiemesz,temp1z,vlag1z,tm.Hour,tm.Minute,unites,dixiemes,tempvlaga[0],tempvlaga[1],donosbuff,tarabuff,unitesv,dixiemesv);  //i+1 če želiš da se prvi panj začne z 1 in ne z 0



//Serial.println(m1);

//lcd.setCursor(0, 1);
//  lcd.print(tele);

sendSMS();
        
} 

//_______________________________________________________________
void sendSMS()
{
     
  String telef = tele;
//  sim.println("AT");
//   delay(2000);
   
   
  sim.println("AT+IPR=9600");     
  delay(2000);
  
  
//   sim.println("AT+CBAND=ALL_BAND");
// delay(2000);  

 sim.println("AT+CMGF=1"); 
 delay(2000);
sim.println("AT");
   delay(2000);

 sim.println("AT+CMGS=\""+telef+"\"\r\n"); // tale ne deluje
 delay(1000);
 sim.print(m1);        // message to send
  delay(1000);
  sim.print((char)26);// End AT command with a ^Z, ASCII code 26
  delay(8500);   // give module time to send SMS
  
}

// NASTAVI URO *****************************************************************
void nastaviuro() {
myGLCD.setFont(SmallFont);

  tmElements_t tm;

if( preklop==0 ){// nastavi uro
 
  odsteva();
  delay(1000);

  tmElements_t tm;
 RTC.read(tm);

 Hour[0]=tm.Hour;
 Hour[1]=tm.Minute;
 Hour[2]=tm.Second;
  Hour[3]=tm.Day;
   Hour[4]=tm.Month;
    tm.Year=tm.Year-96;
   Hour[3]=tm.Year;

 preklop=1;
 }

if(digitalRead (12) == HIGH) {
      preklop=preklop+1;
      delay(800);
    }// tipka preklop


if(preklop==1){   // nastavi uro
//  display.setCursor(63,0);
   myGLCD.print("ura",15,0);;
if(digitalRead (10) == HIGH)  //
{
    Hour[0]=( Hour[0]+1);
if( Hour[0] >= 25)  // 
{
  Hour[0]=1;
myGLCD.printNumI( Hour[0],0,0);
}

 }  
 myGLCD.printNumI(Hour[0],0,0);
}
// //*********************************************************************************************************************
 if(preklop==2){   // nastavi minute
   myGLCD.print("min",15,10);
    if(digitalRead (10) == HIGH)  //
{
  Hour[1]=Hour[1]+1;
   if(Hour[1] >= 60)  // 
{
  Hour[1]=0; 
}
 }  
 myGLCD.printNumI(Hour[1],0,10); 
}

// //*********************************************************************************************************************
 if(preklop==3){   // nastavi minute
   myGLCD.print("sec",15,20);
    if(digitalRead (10) == HIGH)  //
{
  Hour[2]=Hour[2]+1;
   if(Hour[2] >= 60)  // 
{
  Hour[2]=0; 
}
 }  
 myGLCD.printNumI(Hour[2],0,20); 
}
if(preklop==4){
  myGLCD.clrScr();
 preklop=5; 
}

// //*********************************************************************************************************************
 if(preklop==5){   // nastavi minute
   myGLCD.print("dan",15,0);
    if(digitalRead (10) == HIGH)  //
{
  Hour[3]=Hour[3]+1;
   if(Hour[3] >= 32)  // 
{
  Hour[3]=0; 
}
 }  
 myGLCD.printNumI(Hour[3],0,0); 
}
// //*********************************************************************************************************************
 if(preklop==6){   // nastavi minute
   myGLCD.print("mesec",15,10);
    if(digitalRead (10) == HIGH)  //
{
  Hour[4]=Hour[4]+1;
   if(Hour[4] >= 13)  // 
{
  Hour[4]=0; 
}
 }  
 myGLCD.printNumI(Hour[4],0,10); 
}
// //*********************************************************************************************************************
 if(preklop==7){   // nastavi minute
   myGLCD.print("leto",15,20);
    if(digitalRead (10) == HIGH)  //
{
  Hour[5]=Hour[5]+1;
   if(Hour[5] >= 99)  // 
{
  Hour[5]=0; 
}
 }  
 myGLCD.printNumI(Hour[5],0,20); 
}

if(preklop==7){ 
  
 static time_t tLast;
    time_t t;

      tm.Year = Hour[5];
      tm.Month = Hour[4];
            tm.Day = Hour[3];
            tm.Hour = Hour[0];
            tm.Minute = Hour[1];
            tm.Second = Hour[2];
            t = makeTime(tm);

            RTC.set(t);        //use the time_t value to ensure correct weekday is set
            setTime(t); 
            delay(500);

//            display.print("nastavljeno");
//            nastavialarem();
//           display.clearDisplay();

  
}
 //*****************************************************************************************************************

delay(800);
myGLCD.update();

nastaviuro();
}

void odsteva() {

  myGLCD.print("2",0,0);
 myGLCD.update();

  delay(1000);

  myGLCD.print("1",0,0);
  myGLCD.update();

  delay(1000);

  myGLCD.print("0",0,0);
myGLCD.update();

}

thus, it approximately looks whole.

I think the problem is in such code,
how could I make such a shape?

You want to make recursive code? :open_mouth:

i don't know what that means, i would need something like that

Trust me, you do not need or want unlimited recursion on such a tiny processor.

What are you wanting/trying to do?

Recursion: think about it: when you call a function, the function doing the calling pushes a return address onto the stack and jumps to the start of the called function.
If you never return from that function, but call it again, you're very soon going to run out of stack.

I have always liked the dictionary definition of recursion

Recursion : see Recursion

4 Likes

Instead of recursion try tasks, see my tutorial on Multi-tasking in Arduino

multitaskingDiagramSmall

thanks for the answers, I understand better.
I wanted to have, settings only at startup, when a certain key is pressed.
if I do this it will work better?

does anyone have a better idea for setting the clock?

Then do it in setup()