-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRpm.rr
49 lines (36 loc) · 1.04 KB
/
Rpm.rr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//***********************************************//
//******** Inductive Spark Plug Sensor***********//
//************ RPM Meter Shift Light ************//
//******************with Arduino*****************//
//***********************************************//
//**********Designed and Programmed**************//
//************by Kostas Kokoras******************//
//************[email protected]*****************//
const int ignitionPin = 2;
const int ignitionInterrupt = 0;
const unsigned int pulsesPerRev = 1;
unsigned long lastPulseTime = 0;
unsigned long rpm = 0;
int rpm_int;
int rpm_to_disp;
void setup() {
Serial.begin(9600);
pinMode(ignitionPin, INPUT);
attachInterrupt(ignitionInterrupt, &ignitionIsr, RISING);
}
void ignitionIsr()
{
unsigned long now = micros();
unsigned long interval = now - lastPulseTime;
if (interval > 5000)
{
rpm = 60000000UL/(interval * pulsesPerRev);
lastPulseTime = now;
//rpm_int=int(rpm);
}
}
void loop() {
noInterrupts();
rpm_to_disp=int(rpm);
interrupts();
}