PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

47 行
1.6KB

  1. /* Encoder Library - NoInterrupts Example
  2. * http://www.pjrc.com/teensy/td_libs_Encoder.html
  3. *
  4. * This example code is in the public domain.
  5. */
  6. // If you define ENCODER_DO_NOT_USE_INTERRUPTS *before* including
  7. // Encoder, the library will never use interrupts. This is mainly
  8. // useful to reduce the size of the library when you are using it
  9. // with pins that do not support interrupts. Without interrupts,
  10. // your program must call the read() function rapidly, or risk
  11. // missing changes in position.
  12. #define ENCODER_DO_NOT_USE_INTERRUPTS
  13. #include <Encoder.h>
  14. // Beware of Serial.print() speed. Without interrupts, if you
  15. // transmit too much data with Serial.print() it can slow your
  16. // reading from Encoder. Arduino 1.0 has improved transmit code.
  17. // Using the fastest baud rate also helps. Teensy has USB packet
  18. // buffering. But all boards can experience problems if you print
  19. // too much and fill up buffers.
  20. // Change these two numbers to the pins connected to your encoder.
  21. // With ENCODER_DO_NOT_USE_INTERRUPTS, no interrupts are ever
  22. // used, even if the pin has interrupt capability
  23. Encoder myEnc(5, 6);
  24. // avoid using pins with LEDs attached
  25. void setup() {
  26. Serial.begin(9600);
  27. Serial.println("Basic NoInterrupts Test:");
  28. }
  29. long position = -999;
  30. void loop() {
  31. long newPos = myEnc.read();
  32. if (newPos != position) {
  33. position = newPos;
  34. Serial.println(position);
  35. }
  36. // With any substantial delay added, Encoder can only track
  37. // very slow motion. You may uncomment this line to see
  38. // how badly a delay affects your encoder.
  39. //delay(50);
  40. }