// https://wokwi.com/projects/417713685639409665
// From https://github.com/PaulStoffregen/Encoder/blob/master/examples/TwoKnobs/TwoKnobs.ino
// with updates of pins to use interrupts on the clock pins
// and a modern baud rate for speed.
// See also 
//  https://wokwi.com/projects/417713987244523521 -- Basic
//  https://wokwi.com/projects/417713685639409665 -- TwoKnobs
//  https://docs.wokwi.com/parts/wokwi-ky-040 -- Wokwi's encoder
// https://forum.arduino.cc/t/wokwi-simulations-for-arduino-built-in-examples/1304754/9 -- forum discussion

/* Encoder Library - TwoKnobs Example
 * http://www.pjrc.com/teensy/td_libs_Encoder.html
 *
 * This example code is in the public domain.
 */

#include <Encoder.h>

// Change these pin numbers to the pins connected to your encoder.
//   Best Performance: both pins have interrupt capability
//   Good Performance: only the first pin has interrupt capability
//   Low Performance:  neither pin has interrupt capability
Encoder knobLeft(2, 4);
Encoder knobRight(3, 5);
//   avoid using pins with LEDs attached

void setup() {
  Serial.begin(115200);
  Serial.println("TwoKnobs Encoder Test:");
}

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);
  }
}
ScopeBreakout