Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double counting pulse #100

Open
Zin9xhp opened this issue Jan 11, 2024 · 1 comment
Open

Double counting pulse #100

Zin9xhp opened this issue Jan 11, 2024 · 1 comment

Comments

@Zin9xhp
Copy link

Zin9xhp commented Jan 11, 2024

Please use this form only to report code defects or bugs.

For any question, even questions directly pertaining to this code, post your question on the forums related to the board you are using.

Arduino: forum.arduino.cc
Teensy: forum.pjrc.com
ESP8266: www.esp8266.com
ESP32: www.esp32.com
Adafruit Feather/Metro/Trinket: forums.adafruit.com
Particle Photon: community.particle.io

If you are experiencing trouble but not certain of the cause, or need help using this code, ask on the appropriate forum. This is not the place to ask for support or help, even directly related to this code. Only use this form you are certain you have discovered a defect in this code!

Please verify the problem occurs when using the very latest version, using the newest version of Arduino and any other related software.

----------------------------- Remove above -----------------------------

Description

Describe your problem.
When I use this library to count pulses, I receive double counts. Why?

Steps To Reproduce Problem

Please give detailed instructions needed for anyone to attempt to reproduce the problem.

Hardware & Software

Board
Shields / modules used
Arduino IDE version
Teensyduino version (if using Teensy)
Version info & package name (from Tools > Boards > Board Manager)
Operating system & version
Any other software or hardware?

Arduino Sketch

// Change the code below by your sketch (please try to give the smallest code that demonstrates the problem)
#include <Arduino.h>

// libraries: give links/details so anyone can compile your code for the same result

void setup() {
}

void loop() {
}

Errors or Incorrect Output

If you see any errors or incorrect output, please show it here. Please use copy & paste to give an exact copy of the message. Details matter, so please show (not merely describe) the actual message or error exactly as it appears.

@samzmann
Copy link

I'm also facing this issue when running the Basic.ion example. I can get around this problem by checking modulo 2 in the condition (see code below), but that seems totally hacky and unnecessary. Any idea how to fix this double increment problem? I'm on a Teensy 4.1

void loop() {
  long newPosition = myEnc.read();
+  if (newPosition != oldPosition && newPosition % 2 == 0) {
-  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants