Arduino Uno stuck in the delay function

Dears, I'm new with Arduino, I'm using Arduino Uno in a project to control three motors, where they should start start at a specific time, so that I used the RTC module, and they should work one by one seperated by an interval of time, and I'm facing a strange behavior, the program stuck in the delay function, my code is as below:

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;
const int hour_s = 9;
const int min_s = 30;
const int delayCount = 1; //delay in minutes
const int SwArr[3]={4,5,6};
const int MoArr[3]={8,9,10};
unsigned long currentMillis = millis();

void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);

attachInterrupt(digitalPinToInterrupt(2), closing_loop, LOW);
attachInterrupt(digitalPinToInterrupt(3), startup_raining, LOW);

Serial.begin(9600);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) blinking();//RTC.adjust(DateTime(DATE, TIME));
}

void loop()
{
DateTime now = RTC.now();
if (now.hour() == hour_s && now.minute() == min_s) startup_raining();
}

void blinking()
{
int x = 0;
do
{
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
} while (x == 0);
}

void startup_raining()
{
int m = (sizeof(SwArr) / sizeof(SwArr[0]));
for (int i=0; i < m; i++)
{
digitalWrite(MoArr*, LOW);*
_ while (digitalRead(SwArr*) == HIGH)_
_ digitalWrite(MoArr, HIGH);
DateTime nowplus = RTC.now().unixtime() + (delayCount * 60); //the program stuck here!!
while (!(RTC.now().unixtime() - nowplus.unixtime()) <= 0)
digitalWrite(MoArr, LOW);
while (digitalRead(SwArr) == LOW)
digitalWrite(MoArr, HIGH);
}
}
void closing_loop()
{
int m = (sizeof(SwArr) / sizeof(SwArr[0]));
for (int i=0; i < m; i++)
{
if (digitalRead(SwArr) == LOW) {
digitalWrite(MoArr, LOW);
while (digitalRead(SwArr) == LOW) {}
digitalWrite(MoArr, HIGH);
//turnOff(i);
}
delay(1000);
}
}*_

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup (the italics in your code above for example), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

From attachInterrupt() - Arduino Reference

Notes and Warnings

Note
Inside the attached function, delay() won’t work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function. See the section on ISRs below for more information.

This is causing you to get stuck in an endless while loop because the time doesn't ever increment. You're trying to do WAY too much in your interrupt handler functions. In fact, I don't think there is even a good reason for you to be using interrupts at this point.

Hi Pert,
Many thanks for your fast reply, and your guidance :slight_smile: :slight_smile: :slight_smile: