Advertisement
Zaganu

Arduino Encoder by Paul Stoffregen

Jun 4th, 2020
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // MUST INSTALL lib - Encoder by Paul Stoffregen
  2.  
  3.  
  4. /* Encoder Library - Basic Example
  5.  * http://www.pjrc.com/teensy/td_libs_Encoder.html
  6.  *
  7.  * This example code is in the public domain.
  8.  */
  9.  
  10. #include <Encoder.h>
  11.  
  12. // Change these two numbers to the pins connected to your encoder.
  13. //   Best Performance: both pins have interrupt capability
  14. //   Good Performance: only the first pin has interrupt capability
  15. //   Low Performance:  neither pin has interrupt capability
  16. Encoder myEnc(5, 6);
  17. //   avoid using pins with LEDs attached
  18.  
  19. void setup() {
  20.   Serial.begin(9600);
  21.   Serial.println("Basic Encoder Test:");
  22. }
  23.  
  24. long oldPosition  = -999;
  25.  
  26. void loop() {
  27.   long newPosition = myEnc.read();
  28.   if (newPosition != oldPosition) {
  29.     oldPosition = newPosition;
  30.     Serial.println(newPosition);
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement