PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2KB

  1. /* Encoder Library - TwoKnobs Example
  2. * http://www.pjrc.com/teensy/td_libs_Encoder.html
  3. *
  4. * This example code is in the public domain.
  5. */
  6. #include <Encoder.h>
  7. // Change these pin numbers to the pins connected to your encoder.
  8. // Best Performance: both pins have interrupt capability
  9. // Good Performance: only the first pin has interrupt capability
  10. // Low Performance: neither pin has interrupt capability
  11. Encoder knobLeft(5, 6);
  12. Encoder knobRight(7, 8);
  13. // avoid using pins with LEDs attached
  14. void setup() {
  15. Serial.begin(9600);
  16. Serial.println("TwoKnobs Encoder Test:");
  17. }
  18. long positionLeft = -999;
  19. long positionRight = -999;
  20. void loop() {
  21. long newLeft, newRight;
  22. newLeft = knobLeft.read();
  23. newRight = knobRight.read();
  24. if (newLeft != positionLeft || newRight != positionRight) {
  25. Serial.print("Left = ");
  26. Serial.print(newLeft);
  27. Serial.print(", Right = ");
  28. Serial.print(newRight);
  29. Serial.println();
  30. positionLeft = newLeft;
  31. positionRight = newRight;
  32. }
  33. // if a character is sent from the serial monitor,
  34. // reset both back to zero.
  35. if (Serial.available()) {
  36. Serial.read();
  37. Serial.println("Reset both knobs to zero");
  38. knobLeft.write(0);
  39. knobRight.write(0);
  40. }
  41. }