SHARE
TWEET

Untitled

a guest Jun 26th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top