Making speedometer need help with timer and interrupts

Hello, I’m making small project and I need to read speed from my car. The car send 4000 impulses for one mile. I wrote this but it is not even compiling… :

``````#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
volatile int IRQcount;
volatile int IRQcounted;
int pin = 7;
int pin_irq = 4;

void setup() {
lcd.begin(16,2);
attachInterrupt(pin_irq, TIMER1_OVF_vect, FALLING);
TCCR1A = 0x00;
TCNT1 = 3036; // 64 for 1/4 of sec
TCCR1B |= ((1 << CS10) | (1 << CS11));
TIMSK1 |= (1 << TOIE1);
}

ISR(TIMER1_OVF_vect) {

TCNT1 = 3036;
....
IRQcount++;
IRQcounted = IRQcount;
IRQcount == 0;
....
TCNT1 = 3036;
}

void loop() {

int result = IRQcounted;
float speed = (result/4000)*3600
lcd.setCursor (0,0);
lcd.print(speed);
delay(200);

}
``````

I writed this fast so maybe speed algoritm is wrong but I need to know how tu make that timer interrupt. I want it to count all impulses in every 1 sec. How to do that?

Edit. I have Arduino Leonardo

``````  IRQcount == 0;
....
TCNT1 = 3036;
``````

Not compiling, you say? Hmmm.

Ok, i deleted that dots. But i think there is interrupt problem here. I don't know i can write that:

``````attachInterrupt(pin_irq, TIMER1_OVF_vect, FALLING);
``````

I mean that TIMER1_OVF_vect . I think it is wrong. Can anyone explain me how to fix that?

Try this

What exactly do you mean? I just want to know how it should look like...

giebeka: What exactly do you mean? I just want to know how it should look like...