Interrupting delay; command

Howdy

I have code that I took from here and a bit changed it for myself - hackster.
What I need is to stop command delay; lasting for hour, and return to begining. I tried to do that with return; but it executing, of course, after delay. Can somebody hint me?
Here is my changed code:

int buzzerPin = 8;  //The Buzzer pin
int redLed1 = 9;     //The led pin
   int redLed2 = 10;
   int redLed3 = 11;
int moisture1;       //The moisture value
 int moisture2;
 int moisture3;
 
void setup() {
  pinMode(buzzerPin,OUTPUT);   
  pinMode(redLed1,OUTPUT);
  pinMode(redLed2,OUTPUT);  
  pinMode(redLed3,OUTPUT);       
}
 
void loop() {

  moisture1 = analogRead(A0);            
   //Read the moisture from sensor
  moisture1 = map(moisture1,0,1023,100,1); 
    //Map the moisture values to 1-100. 
  if (moisture1 < 50) {                   
    //If moisture is low
    digitalWrite(redLed1,HIGH);          
//Turn on the led light with its number
    tone(buzzerPin, 2000, 500);          
 //Play a buzzer tone for half a second
    delay(3600000);
    if (moisture1 > 50) {
      return; 
      }                    
  //wait a hour 
//Delay another second
  } else {                               
 //If moisture is OK
    digitalWrite(redLed1,LOW);           
 //Just turn off the leds
  }
  
 moisture2 = analogRead(A1);            
   //Read the moisture from sensor
  moisture2 = map(moisture2,0,1023,100,1); 
    //Map the moisture values to 1-100. 
  if (moisture2 < 50) {                   
    //If moisture is low
    digitalWrite(redLed2,HIGH);          
//Turn on the led light with its number
    tone(buzzerPin, 2000, 500);          
 //Play a buzzer tone for half a second
  if (moisture2 > 50) {
      return; 
      } 
    delay(3600000);                    
  //wait a hour 
//Delay another second
  } else {                               
 //If moisture is OK
    digitalWrite(redLed2,LOW);           
 //Just turn off the leds
  }
  
  moisture3 = analogRead(A2);            
   //Read the moisture from sensor
  moisture3 = map(moisture3,0,1023,100,1); 
    //Map the moisture values to 1-100. 
  if (moisture3 < 50) {                   
    //If moisture is low
    digitalWrite(redLed3,HIGH);          
//Turn on the led light with its number
    tone(buzzerPin, 2000, 500);          
 //Play a buzzer tone for half a second
    delay(3600000); 
     if (moisture3 > 50) {
      return; 
      }                    
  //wait a hour 
//Delay another second
  } else {                               
 //If moisture is OK
    digitalWrite(redLed3,LOW);           
 //Just turn off the leds
  }
}

Can somebody hint me?

Sure - don't use delay.

There is a topic pinned at the top of the forum discussing the use of millis() - may be good to read

J-M-L:
There is a topic pinned at the top of the forum discussing the use of millis() - may be good to read

That kinda helpful.
Will read one day...

Then maybe can be such command, for example, so buzzer not beeped more than once in hour in anyway what in code, so I can change delay ammount? On my code example.

I'm sorry, I don't understand the question.

cookins:
That kinda helpful.
Will read one day...

I think the idea was that you would read it and study it carefully before asking your next question. Then maybe you would figure out how to do it and not need to ask any more questions about that problem.

...R

cookins:
That kinda helpful.
Will read one day...

Then maybe can be such command, for example, so buzzer not beeped more than once in hour in anyway what in code, so I can change delay ammount? On my code example.

Yes, there is a way. It is explained in that link. One day when you get around to reading it you will learn the answer you seek. Until then, if you are too lazy to read the link then don't expect that anyone here is going to spoon feed it to you.

You guys ALL same helpful
Thanks for link!

Topic can be closed

OK
I’ll provide an answer... one day... :slight_smile:

Come back when you’ve grown up and can take an advice