Look at the pin, if it's just changed then record the micros and calculate RPM or whatever
Do other stuff.
The other stuff should take a very small amount of time. If you have a long-running task, like debouncing a switch (which takes 10-20 milliseconds) then just do a little bit of the task each time. (Record the time the bounce was detected and compare it to the last movement of the button.) Don't ever stop and wait with a function like pulseIn() or delay().
Wonder why no-one tripped over this: you're wasting three bytes here. Why use a 4-byte variable when 1 byte is enough? Use a uint_8 or byte instead. This particular variable will be cleaned up when the loop is done, so here it doesn't matter much, but for other variables it does. And that can make a big difference when trying to make your code fit in the Arduino memory.
Oh, and please use code tags around your code. Makes it so much more readable. It's the </> button in the full editor.
You both are rigth.
Thanks for this information. I copied that code from somewhere. Probably it was reading a longer pulse count. Not sure from where but
MorganS.
Can you give me an example code. As i am realy stuck.
Can you give me an example code. As i am realy stuck.
Look at the StateChangeDetection example in the IDE. It shows how to detect the change of state from one to another. When the state change occurs record the value of micros() or millis() as appropriate for the speed of the system. When the next change occurs do the same and use the difference between the time values to calculate the RPM.