Electgpl

ARDUINO - Encoder Rotativo con boton

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