Interruptions problem

Hello to everybody

I´m new in the forum. First of all I would like to apologize about my english, I am from Spain and your language is not my best skill.
I am developing a laptimer for my motorcycle, triggered by the interruption 0 (pin 2 in the Arduino UNO). The thing is that I have programmed a "blind time" where the laptimer is not supposed to get triggered.

The problem that I´m having is that when that "blind time" is going on and the Arduino pin 2 receives a FALLING edge pulse, the microcontroller keeps that trigger signal until the blind time is over, and then it counts a new lap with the exactly same time as the "blind time" .
Could you help me troubleshooting the code? I have read it like a thousand times but I still don´t get to the problem.
If you don´t understand the code because of the language please let me know and I will try to translate it.
Here is it:

volatile int minutos = 0;
volatile int segundos = 0;
volatile int decimas = 0;
long milisegundos = 0;
int boton = 2;
volatile int i = 0;
volatile int minutosvr= 59;
volatile int segundosvr = 59;
volatile int decimasvr=999;
unsigned int t_oscuro = 10000; //Tiempo de oscuridad de 10 segundos
unsigned long lastmillis = 0;
boolean interrupt_activ;

void setup(){
  Serial.begin(9600);
  pinMode(boton, INPUT);
  digitalWrite(boton, HIGH);
 
 
}


  //Restart button
  void reinicio(){
    
   i = i++;
    if(minutos<minutosvr || minutos==minutosvr && segundos<segundosvr || minutos==minutosvr && segundos==segundosvr && decimas<decimasvr){
     minutosvr= minutos;
     segundosvr = segundos;
     decimasvr= decimas;
    }
    
    minutos=0;
    segundos=0;
    decimas=0; 
    lastmillis = millis();    
  }
  



void loop(){
  
 
  if (millis()-lastmillis > t_oscuro){   //If the blind time has past
    if (interrupt_activ == false){        //Attach again the interrupt
      attachInterrupt(0, reinicio, FALLING); 
      interrupt_activ = true;
    }else if (interrupt_activ == true){  //If the interrupt is attached, wait until it gets triggered   
    }
    
    
  }else if (millis()-lastmillis <= t_oscuro){  //If the blind time is not over
    if (interrupt_activ == true){                
       detachInterrupt(0);  //Dettach the interrupt
       interrupt_activ = false;
    }else if(interrupt_activ == false){}
  }
  
  
  
  milisegundos = millis();
  if(milisegundos % 100 == 0){ //Only enter if it has passed tenth of a second
    decimas++;
    if(decimas == 10){ //When it has passed 10 tenths of a second it count one second
      decimas = 0;
      segundos++;
    }
    if(segundos == 60){ //When it has passed 60 seconds it count one minute
      segundos = 0;
      minutos++;
    }
    
    //Screen print the data
    if(minutos < 10){
      Serial.print("0");
    }
    Serial.print(minutos);
    Serial.print(":");
    
    if(segundos < 10){
      Serial.print("0");
    }
    Serial.print(segundos);
    Serial.print(":");    
    Serial.print(decimas);
    Serial.print("            ");
    
    if(minutosvr < 10){
      Serial.print("0");
    }
    Serial.print(minutosvr);
    Serial.print(":");
    
    if(segundosvr < 10){                  //tiempo vuelta rápida
      Serial.print("0");                  //tiempo vuelta rápida
    }                                     //tiempo vuelta rápida
    Serial.print(segundosvr);             //tiempo vuelta rápida
    Serial.print(":");                    //tiempo vuelta rápida
    Serial.print(decimasvr);              //tiempo vuelta rápida
    Serial.print("             ");    //tiempo vuelta rápida
    Serial.print(i);                    //número de vueltas completadas
    Serial.print("           ");
    Serial.print(milisegundos);
    Serial.print("      ");
    Serial.println(interrupt_activ);
  }

  
}

Thank you all for your help!

Why are you attaching and detaching the interrupt in loop() ? If you want interrupts not to trigger for a period then disable them using noInterrupts() as long as nothing else that depends on them is happening.

However, the main question is, why are you using interrupts in the first place ?

UKHeliBob:
However, the main question is, why are you using interrupts in the first place ?

His motorbike is fitted with flux capacitors :smiley: :smiley: :smiley: :smiley:

I am attaching and detaching it because I dont want the laptimer to get triggered until a certain amount of time has past (there could be other beacons on the pit wall). Also because I´m using a beacon with a 5 ms period square signal, and this way is the easiest one to avoid multi triggering.

I am using interrupts because of the high frequency of the signal. I am afraid that using the polling method would probably miss some signal. Do you recomend me any other method?

In the Spanish forum recomend me to use an empty dummie function, and call it instead of detaching the interruption, and it worked good.

Thank you all for your help, and if you think of any other way to get it working or just a more efficient one and you like to contribute do not hesitate to post it!

I am attaching and detaching it because .........

That is absolutely no reason to attach and detach. There is nothing that would not be covered by the disable interrupts.

In the Spanish forum recomend me to use an empty dummie function, and call it instead of detaching the interruption, and it worked good.

Equally as silly as attaching and detaching.

I am afraid that using the polling method would probably miss some signal

Why? You don't appear to be doing much else in the loop function.

How long (in seconds) is a lap?

How much error (in milliseconds) is acceptable for the lap time?

Assuming the answer to the second question is 1 or more then polling the sensor will be perfectly adequate and a lot less trouble.

...R