Michel Jansen

Member Since: February 28, 2011

Country: United States

  • Product COM-09117 | about 3 years ago

    For whoever may find it useful: I used a bunch of these rotary encoders for a prototyping project and I wrote a simple wrapper library around them.
    You can find the code on GitHub:
    https://github.com/micheljansen/arduino-rotary-knob
    #define PIN_OFFSET 22
    #define NUMKNOBS 6
    Knob knobs[NUMKNOBS];
    void setup()
    {
    for(int i = 0; i < NUMKNOBS; i++) {
    knobs[i].setup(PIN_OFFSET + 2i, PIN_OFFSET + 2i + 1);
    // abuse output pins for gnd
    pinMode(i+2, OUTPUT);
    digitalWrite(i+2, LOW);
    }
    Serial.begin(9600);
    }
    void loop()
    {
    for(int i = 0; i < NUMKNOBS; i++) {
    int dir = knobs[i].read();
    if(dir) {
    if(dir > 0) {
    Serial.println(“right”);
    }
    else {
    Serial.println(“left”);
    }
    }
    }
    }

No public wish lists :(