-
• #2
It matchs 4 time for 1 step
-
• #3
i've corrected my pb with an ugly trick but it works as i need.
it sends through the serial :
1
for clockwise and pulse Green led
-1
for conterclockwise and pulse Red ledfunction onInit() { var step = 0; var final = 0; require("Encoder").connect(A5, A8, (temp) => { step += temp; if (Math.floor(step / 4) == step / 4) { (step > 0) ? dir = 1: dir = -1; step = 0; (dir > 0) ?digitalPulse(LED1, 1, 20):digitalPulse(LED2, 1, 20); print(dir); } }); }
-
• #4
no more answer than mine... okay it's not really interesting, nevermind... there is a glitch in the lib...
and my attempt is not 100% efficient.
if I turn the encoder quickly, the algorithm slips, and the number advances slowly with a step backwards from time to time...a better idea than mine?
regards
éric
-
• #5
Sorry - I thought from the above that you may have sorted it... Espruino does actually include the ability to monitor a pin in a setWatch, so that may help you:
var value = 0; setWatch(function(e) { if (e.data) value++ else value--; print(value); }, A5, {data:A8, repeat:true});
I notice you're doing a
print
anddigitalPulse
. Is it possible that turning the knob quick is creating so many events that the functions can't be called quick enough and so it loses track? -
• #6
Thanks Gordon
i've commented the digitalPulse and print to minimize the interference...
i send through HID
i'll try your code tonight.é.
-
• #8
That is strange... Do the pins need pullups?
Maybe swap
A5
andA8
in the code and see if that helps. Also maybe you needededge:'falling'
in the watch.Usually in an encoder, when one pin changes state, the state of the other pin determines the angle. But in this case I guess because we were reacting on both edges of A5, we'd just end up adding and subtracting from
value
-
• #9
OK thank you @Gordon
the final solution was the pull_up
function onInit() { var value = 0; pinMode(A8, 'input_pullup'); pinMode(A5, 'input_pullup'); setWatch(function(e) { if (e.data) value++ else value--; print(value); }, A5, {data:A8, repeat:true, edge:'falling'}); }
the value increases and decreases according to the rotation.
é.
Hello,
i'm playing with a rotary encoder a big MYSM60-100PPRR-5L with the example given
but the console is populated with too many answer for 1 step.
console return for 1step backward
and
for 1 step forward...
what i'm doing badly?