remote control and delay problem

I want to run for 2 minutes and shuts off for 4 minutes I add function to stop by remote control but the problem is that the remote command is not received until the end of the delay
help in modifying the code

#include <IRremote.h>
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
int buttonState = 0;
int lastpressed = 0;
int i = 1;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); 
pinMode(13, OUTPUT);  
}

void loop() {
unsigned long codeValue;
  if (irrecv.decode(&results) ) {
Serial.println (results.value, DEC) ;
  
  codeValue = results.value;
      irrecv.resume(); 
  }
   if (codeValue == 83579055){
   i = 1;
  } 
   if (codeValue == 83570895){
   i = 0;
   }

if (i == 1){
   digitalWrite(13, HIGH);
   delay(120000);  
   digitalWrite(13, LOW);
   delay(240000);  
} else {

   digitalWrite(13, LOW); 

     } 

delay(10);
}

BlinkWithoutDelay example. Learn it. Live it. Love it.

Rewrite it following blink without delay methodology.

I tried and I didn't succeed

brraaq: I tried and I didn't succeed

That's too bad. We could probably help if we saw what you tried.

Try again and ask for us for help.

#include <IRremote.h>
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
int buttonState = 0;
int lastpressed = 0;
int i = 1;
long time2 = 120000;    
long time4 = 240000;    
void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); 
pinMode(13, OUTPUT);  
}

void loop() {

unsigned long codeValue;
  if (irrecv.decode(&results) ) {
Serial.println (results.value, DEC) ;
  
  codeValue = results.value;
      irrecv.resume(); 
  }
   if (codeValue == 83579055){
   i = 1;
  } 
   if (codeValue == 83570895){
   i = 0;
   }

if (i == 1){
   digitalWrite(13, HIGH);
   unsigned long time2 = millis();
   digitalWrite(13, LOW);
   unsigned long time4 = millis();
} else {

   digitalWrite(13, LOW); 

     } 

delay(10);
}

led blink very fast 0.1 sec

All you are doing is recording the time, you're not doing anything with it. Notice how in the BlinkWithoutDelay example, there is an if statement involving the previous recorded time?

now it’s work but with same time for on and off
thank you and check the code

#include <IRremote.h>
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
int buttonState = 0;
int lastpressed = 0;
int i = 1;
 long previousMillis = 0;   
long interval = 120000;  
int ledState = HIGH; 
const int ledPin =  13; 
void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn(); 
pinMode(13, OUTPUT);  
}

void loop() {

unsigned long codeValue;
  if (irrecv.decode(&results) ) {
Serial.println (results.value, DEC) ;
  
  codeValue = results.value;
      irrecv.resume(); 
  }
   if (codeValue == 83579055){
   i = 1;
  } 
   if (codeValue == 83570895){
   i = 0;
   }

   if ( i == 1 ) {
       digitalWrite(ledPin, ledState);
       unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
   }
   } else {
     digitalWrite(ledPin, LOW);
   }

delay(10);
}

So when you turn it on, set interval to whatever the off interval is. When you turn it off, set interval to whatever the on interval is.