@Gordon: Is it not cheaper to calculate the speed just every few seconds than adding more logic into each wheel turn? In addition, caluclating the time in the watch function, I get some problems:
lastTime is the time in seconds at which the pin last changed state. When using edge:'rising' or edge:'falling', this is not the same as when the function was last called.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Sorry, I don't understand the discussion regard reed switch or not.
I modified the code so that the interval timer is deactivate if the speed is 0. It's activated again by the first rotation: https://github.com/avanc/espruino-tachomĀeter/blob/master/tachometer.js
@Gordon: Is it not cheaper to calculate the speed just every few seconds than adding more logic into each wheel turn? In addition, caluclating the time in the watch function, I get some problems: