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.

45 lines
1.2 KiB

5 years ago
  1. // -----
  2. // SimplePollRotator.ino - Example for the RotaryEncoder library.
  3. // This class is implemented for use with the Arduino environment.
  4. // Copyright (c) by Matthias Hertel, http://www.mathertel.de
  5. // This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
  6. // More information on: http://www.mathertel.de/Arduino
  7. // -----
  8. // 18.01.2014 created by Matthias Hertel
  9. // -----
  10. // This example checks the state of the rotary encoder in the loop() function.
  11. // The current position is printed on output when changed.
  12. // Hardware setup:
  13. // Attach a rotary encoder with output pins to A2 and A3.
  14. // The common contact should be attached to ground.
  15. #include <RotaryEncoder.h>
  16. // Setup a RoraryEncoder for pins A2 and A3:
  17. RotaryEncoder encoder(A2, A1);
  18. void setup()
  19. {
  20. Serial.begin(9600);
  21. Serial.println("SimplePollRotator example for the RotaryEncoder library.");
  22. } // setup()
  23. // Read the current position of the encoder and print out when changed.
  24. void loop()
  25. {
  26. static int pos = 0;
  27. encoder.tick();
  28. int newPos = encoder.getPosition();
  29. if (pos != newPos) {
  30. Serial.print(newPos);
  31. Serial.println();
  32. pos = newPos;
  33. } // if
  34. } // loop ()
  35. // The End