• Hello,
    I tried to use the Encoder module with a rotary encoder (http://www.amazon.com/dp/B00HSX9ZB2).

    var step = 0;
    require("Encoder").connect(A1,A2,functio­n (direction) {
        step += direction;
        print(step);
    });
    

    step will be incremented/decremented by 2 on every notch. This is not expected when looking at the api but understandable when looking at the implementation. The state machine 00 → 01 → 11 → 11 → .. calls onChange() also in the instable states 01 and 10.

    This is academically correct for general gray codes. But I think that is not the intended behavior for supporting an incremental rotary encoder because client code will now have to skip every second callback. What is your opinion? Who is using this module? How do you deal with these circumstances? Do you use the "Encoder" module for something other than rotary encoders?

    I made an adaption with a more "rotary encoder" behavior - it's attached. If desired I could make a pull request with some additional debounce logic. Debouncing is now possible because of the internal "forbidden" states.

    BTW there is a small bug in the initialization code of the original module. The first step will not be detected correctly. I fix it if the attached new code should not be used.


    1 Attachment

About

Avatar for luwar @luwar started