Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. int encoder0PinA = 7;
  2. int encoder0PinB = 8;
  3. int encoder0Pos = 0;
  4. int encoder0PinALast = LOW;
  5. int n = LOW;
  6.  
  7. void setup() {
  8. pinMode (encoder0PinA,INPUT);
  9. pinMode (encoder0PinB,INPUT);
  10. Serial.begin (9600);
  11. }
  12.  
  13. void loop() {
  14. n = digitalRead(encoder0PinA);
  15. if ((encoder0PinALast == LOW) && (n == HIGH)) {
  16. if (digitalRead(encoder0PinB) == LOW) {
  17. encoder0Pos--;
  18. } else {
  19. encoder0Pos++;
  20. }
  21. Serial.println (encoder0Pos);
  22. // Serial.print ("/");
  23. }
  24.  
  25. encoder0Pos = encoder0Pos % 1024;
  26. encoder0PinALast = n;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement