The fact that you haven't declared the necessary variables volatile?
Okay, so I have declared revolutions and timeold as volatile. I don't have the sensor with me now. But do you think it would work with the code below?
The fact that you haven't removed one of the attachInterrupt calls?
I have only one of the attachInterrupt routines
You haven't told us what changes you've made. All you've done is defend stupid code.
The code below is the changes I have made.
volatile byte revolutions;
unsigned int rpmilli;
float speed;
volatile unsigned long timeold;
float wheel_circ = 1.634;
void setup()
{
Serial.begin(9600);
attachInterrupt(0, rpm_fun, FALLING);
revolutions = 0;
rpmilli = 0;
timeold = 0;
}
void loop()
{
if (revolutions >= 10) {
//Update RPM every 10 counts
// calculate the revolutions per milli(second)
rpmilli = revolutions/(millis() - timeold);
timeold = millis();
revolutions = 0;
speed = rpmilli * wheel_circ/ 1000; // speed in meters per second
speed = 2.237*speed; // speed in miles per hour
Serial.print(" Speed:");
Serial.print(speed,DEC);
Serial.println(" mph");
}
}
void rpm_fun()
{
revolutions++;
}