Program suddenly stopping

I-ve got a simple program that keeps track of the day time, and turns on output in specific hours every few days. But when I start it the code stops working. I managed to find the area which stops it, so I hope u can tell me why it happens.

byte outputPin = 13;
byte frequencyPin = A0;
byte durationTimePin = A1;
byte offsetTimePin = A2;

unsigned long time = 0;
unsigned long lastTime = 0;
unsigned long startTime = 0;

int dayCount = 0;
long hourCount = 0;
int minCount = 0;

unsigned long frequency = 0;
unsigned long durationTime = 0;
unsigned long offsetTime = 0;

void setup() {
  pinMode(outputPin, OUTPUT);

  pinMode(frequencyPin, INPUT_PULLUP);
  pinMode(durationTimePin, INPUT_PULLUP);
  pinMode(offsetTimePin, INPUT_PULLUP);
  
  Serial.begin(9600);
}

void loop() {
  
  if (time<=10){
    frequency = analogRead(frequencyPin);
    frequency = map(frequency, 0, 1023, 10, 168);

    durationTime = analogRead(durationTimePin);
    durationTime = map(durationTime, 0, 1023, 121, 10);
  }

  
  time = millis();
  time = time/60000;

  if (time != lastTime){
    lastTime = time;
    minCount = minCount+1;
  }
//This is the beggining of the problem
  if (minCount/60%0 && minCount/60!=hourCount){
    hourCount = hourCount+1;
    minCount=0;
  }

  if (hourCount/24%0 && hourCount/24 != dayCount){
    dayCount=dayCount+1;
    hourCount=0;
  }
  

  if (dayCount*24+hourCount % 0){
    startTime = time;
    digitalWrite(outputPin, HIGH);
  }
//This is the end of the problem
  if (time-startTime == durationTime){
    digitalWrite(outputPin, LOW);
  }


  Serial.print(time);
  Serial.print("   Minuta: ");
  Serial.print(minCount);
  Serial.print(". Godzina: ");
  Serial.print(hourCount);
  Serial.print(". Dzień: ");
  Serial.print(dayCount);
  Serial.print(".   Podlewać co: ");
  Serial.print(frequency);
  Serial.print(" godz. przez: ");
  Serial.print(durationTime);
  Serial.println(" min.");
}

Hello bartek_bawer

Check for divsion by zero.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.