Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #define ENCODER_PIN 2
  2.  
  3. volatile unsigned long clicks = 0;
  4. unsigned long last_clicks = 0;
  5.  
  6. void setup() {
  7. Serial.begin(9600);
  8.  
  9. // tried INPUT, INPUT_PULLUP and even commenting out the pinMode
  10. pinMode(ENCODER_PIN, INPUT);
  11.  
  12. // tried CHANGE, RISING and FALLING
  13. attachInterrupt(digitalPinToInterrupt(ENCODER_PIN), encoder_isr, CHANGE);
  14.  
  15. Serial.println("Interrupt attached");
  16. }
  17.  
  18. void loop() {
  19. if (clicks != last_clicks) {
  20. Serial.print("Clicks: ");
  21. Serial.println(clicks);
  22. last_clicks = clicks;
  23. }
  24. delay(1000);
  25. }
  26.  
  27. void encoder_isr() {
  28. clicks++;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement