Advertisement
Guest User

Untitled

a guest
Sep 6th, 2014
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  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.  
  7. #include <Encoder.h>
  8.  
  9. // Change these pin numbers to the pins connected to your encoder.
  10. // Best Performance: both pins have interrupt capability
  11. // Good Performance: only the first pin has interrupt capability
  12. // Low Performance: neither pin has interrupt capability
  13. Encoder knobLeft(5, 6);
  14. Encoder knobRight(7, 8);
  15. // avoid using pins with LEDs attached
  16.  
  17. void setup() {
  18. Serial.begin(9600);
  19. Serial.println("TwoKnobs Encoder Test:");
  20. }
  21.  
  22. long positionLeft = -999;
  23. long positionRight = -999;
  24.  
  25. void loop() {
  26. long newLeft, newRight;
  27. newLeft = knobLeft.read();
  28. newRight = knobRight.read();
  29. if (newLeft != positionLeft || newRight != positionRight) {
  30. Serial.print("Left = ");
  31. Serial.print(newLeft);
  32. Serial.print(", Right = ");
  33. Serial.print(newRight);
  34. Serial.println();
  35. positionLeft = newLeft;
  36. positionRight = newRight;
  37. }
  38. // if a character is sent from the serial monitor,
  39. // reset both back to zero.
  40. if (Serial.available()) {
  41. Serial.read();
  42. Serial.println("Reset both knobs to zero");
  43. knobLeft.write(0);
  44. knobRight.write(0);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement