kbell101:
If you count a pulse every time aVal changes state, (LOW to HIGH and HIGH to LOW) and don't otherwise account for it, you will negate your counts and only count the spurious ones. Therefore use aVal only when it transitions from HIGH to LOW (or visa-versa, but this works, so I use it.) This seems to be the reason many have resorted to using Interrupts so they can use FALLING or RISING in their code. A change in the 'if' statement mimics the FALLING interrupt and made it all work with my encoders:
Hi ppl!
I'm fairly new to arduino and programming (I've gone trough the "Arduino Procets Book" and also made some of my own stuff).
Long story short: My Keyes rotary encoder sometimes (or often) get in a state after i rotated it where it keeps increasing(or decreasing) the number in the example code.
I just rotate it a little, and it keeps on going after i stop rotating.
I've tried many of the codes posted here, same result.
Can it have anything to do with the fact that i've connected the switch to pin 5 (with a pull-up resistor. I've tried both a 10k and the internal pullup as suggested by someone here)?
The button seems to work fine though.
When i look at the serial mon it doesn't look like the arduino (pro micro) thinks i'm rotating eitherm even though it keeps going, see below:
PinA: 0 PinB: 1 Counter: 1113
PinA: 0 PinB: 0 Counter: 1114
PinA: 0 PinB: 0 Counter: 1115
PinA: 0 PinB: 1 Counter: 1114
PinA: 0 PinB: 0 Counter: 1115
PinA: 0 PinB: 0 Counter: 1116
PinA: 0 PinB: 0 Counter: 1117
PinA: 0 PinB: 1 Counter: 1116
PinA: 0 PinB: 0 Counter: 1117
This is without me touching the device.