Hi guys
i have tried some stuff now but doesnt work well.
i want to read rpm from a engine (up to 18.000 RPM) via its hall sensor.
i have tried this and have trouble
can you help me with and better or shorter code? thanks
int threshold = 200;
int val;//the digital value of the incoming analog signals
int prev_val = 0;
int t, cur_t; //time variables
void setup()
{
Serial.begin(115200);
pinMode(A0, INPUT);
}
void loop()//Measure RPM
{
int sig = analogRead(A0);
if (sig > threshold) val = HIGH;
else val = LOW;
if (prev_val == 0 && val == 1) { //check for rising edge
cur_t = micros();
Serial.println(1000000 * 60 / (cur_t - t)); //print the rpm
t = micros();
}
prev_val = val;
}