Pb Timer

hi there
if someone can help me to debug my pb on the timer because its working only till 32" but not more
thx

this is the programme:

#include <IRremote.h>

int RECV_PIN = 11;  // récepteur IR à la pin 11

IRrecv irrecv(RECV_PIN);

decode_results results;

int LED_1=2;
int LED_2=3;

int etatRelay_1;  // mémorise l'état du relay_1
int etatRelay_2;  // mémorise l'état du relay_2
unsigned long lastRelaiHighMillis = 0; // mémorise la dernière fois que le relai a été activé
unsigned long maxRelaiHighMillis =40*1000;// Temps maximum d'activation du relai (40 sec)

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); 

  pinMode (LED_1,OUTPUT);
  pinMode (LED_2,OUTPUT);
  etatRelay_1 = LOW;
  etatRelay_2 = LOW;

} 

void action(decode_results *results) {
  int count = results->rawlen;

  if (results->decode_type == UNKNOWN) {

    switch (results->value) {

    case 0xE13DDA28:
      if (digitalRead(3) == HIGH)
      {
        digitalWrite(LED_2,LOW);
        delay(1000); 
        digitalWrite(LED_1,HIGH);
        etatRelay_1=HIGH;
        // Get current time
        unsigned long currentMillis = millis();
        lastRelaiHighMillis = currentMillis;
      }
      else if (digitalRead(3) == LOW){
        digitalWrite(LED_1,HIGH);
        etatRelay_1=HIGH;
        // Get current time
        unsigned long currentMillis = millis();
        lastRelaiHighMillis = currentMillis;
        
      }
      Serial.println("Relay_1");
      delay(50);
      break;

    case 0xAD586662:
      if (digitalRead(2) == HIGH)
      {
        digitalWrite(LED_1,LOW);
        delay(1000); 
        digitalWrite(LED_2,HIGH);
        etatRelay_2=HIGH;
        // Get current time
        unsigned long currentMillis = millis();
        lastRelaiHighMillis = currentMillis;
        
      }
      else if (digitalRead(2) == LOW){
        digitalWrite(LED_2,HIGH);
        etatRelay_2=HIGH;
        // Get current time
        unsigned long currentMillis = millis();
        lastRelaiHighMillis = currentMillis;
        //Serial.println(currentMillis);
      }
      Serial.println("Relay_2");
      //Serial.println(currentMillis);
      break;
      
    case 0x273009C4:
      Serial.println("OK");
      digitalWrite(LED_1,LOW);
      digitalWrite(LED_2,LOW);
      etatRelay_1=LOW;
      etatRelay_2=LOW;
        // Get current time
        unsigned long currentMillis = millis();
        lastRelaiHighMillis = currentMillis;
        //Serial.println(currentMillis);
      break;
    }
  } 
}


void loop() {
  // Get current time
  unsigned long currentMillis = millis();
  unsigned long soustraction=(currentMillis-lastRelaiHighMillis);
  
  
// Faut-il désactivé le relai automatiquement ?
  // Si Relays LOW ne rien Faire
  /*if((etatRelay_1 == LOW)||(etatRelay_2 == LOW)){
    etatRelay_1 = LOW;
    etatRelay_2 = LOW;
    }*/
  if( ((etatRelay_1 == HIGH)||(etatRelay_2 == HIGH)) && (soustraction >= maxRelaiHighMillis ) ) {
    //desactiver relay_1
    etatRelay_1 = LOW;
    etatRelay_2 = LOW;
    digitalWrite(LED_1, etatRelay_1 ); 
    digitalWrite(LED_2, etatRelay_2 ); 
  }
    
  if (irrecv.decode(&results)) {
    action(&results);
    irrecv.resume(); // Receive the next value
    //Serial.println(etatRelay_1,etatRelay_2);
    //Serial.println(currentMillis);
    //Serial.println(millis());
  }
      Serial.println(soustraction);
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Hi, not really sure what your problem is. Perhaps you could provide more detail.

In the meantime it might be worth checking this line:

  if (results->decode_type == UNKNOWN) {.....}

If the result is unknown then the value returned (results->value) will be meaningless.

If the signal is decoded and returns a supported protocol (like NEC) then you can use the ‘value’.

        unsigned long currentMillis = millis();
        lastRelaiHighMillis = currentMillis;

Is this somehow better than:

        lastRelaiHighMillis = millis();
      if (digitalRead(3) == HIGH)
      {
      }
      else if (digitalRead(3) == LOW){

Are you planning to deal with the case where digitalRead() returns something other than HIGH or LOW? What other values can it possibly return?

I don't understand what your problem is, either.

Edit:

unsigned long maxRelaiHighMillis =40*1000;// Temps maximum d'activation du relai (40 sec)

40 is an int. 1000 is an int. Therefore, an int register will be used to store the result, which won't fit.

unsigned long maxRelaiHighMillis =40UL*1000UL;

Now, 40 and 1000 are unsigned longs, so an unsigned long register will be used to hold the result, which will fit.

32 seconds interval... may look like USB-port traffic..

32 seconds interval... may look like USB-port traffic..

Actually, the limit is probably 32.767 seconds...