/* Teensy 4 H/S Encoder Library - TwoKnobs Example * http://www.pjrc.com/teensy/td_libs_Encoder.html * * This example code is in the public domain. */ #include "QuadEncoder.h" // Change these pin numbers to the pins connected to your encoder. // Allowable encoder pins: // 0, 1, 2, 3, 4, 5, 7, 30, 31 and 33 // Encoder on channel 1 of 4 available // Phase A (pin0), PhaseB(pin1), QuadEncoder knobLeft(1, 0, 1); // Encoder on channel 2 of 4 available //Phase A (pin2), PhaseB(pin3), Pullups Req(0) QuadEncoder knobRight(2, 2, 3); // avoid using pins with LEDs attached void setup() { Serial.begin(9600); Serial.println("TwoKnobs Encoder Test:"); /* Initialize Encoder/knobLeft. */ knobLeft.setInitConfig(); knobLeft.init(); /* Initialize Encoder/knobRight. */ knobRight.setInitConfig(); knobRight.init(); } long positionLeft = -999; long positionRight = -999; void loop() { long newLeft, newRight; newLeft = knobLeft.read(); newRight = knobRight.read(); if (newLeft != positionLeft || newRight != positionRight) { Serial.print("Left = "); Serial.print(newLeft); Serial.print(", Right = "); Serial.print(newRight); Serial.println(); positionLeft = newLeft; positionRight = newRight; } // if a character is sent from the serial monitor, // reset both back to zero. if (Serial.available()) { Serial.read(); Serial.println("Reset both knobs to zero"); knobLeft.write(0); knobRight.write(0); } }