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!