You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • A reed switch will tend to 'bounce' because it's a mechanical contact.

    What can happen is that it bounces so fast that the underlying hardware detects a change, but by the time the software gets to check the pin state it has changed again.

    If you're using pullup I'd just to a watch on the falling edge of the signal, and would then just ignore anything that happens less than 50ms after the first detected pulse. You could use debounce but it could get thrown off by the very quick changes I said about above.

    You're storing lastTime anyway, so it should be pretty easy:

    var lastTime;
    var RPM;
    var w=setWatch(function(e) {
      if (e.time<lastTime+0.05) return;
      RPM = 60 / (e.time - lastTime);
      lastTime = e.time;
      counter++;
      },
      pin,
      {repeat: 'true', edge:'rising'}
    );
    
About

Avatar for Gordon @Gordon started