Rotary Encoder Module

  • $5.95


Rotary Encoder Module Code


/* SETUP

Rotary-Encoder  Arduino
GND      -      D2
+        -      5V
SW       -     
DT       -      D4
CL.K     -      D3
*/
 
int val;
int encoder0PinA = 3;
int encoder0PinB = 4;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;

void setup() {
  pinMode (encoder0PinA, INPUT);
  pinMode (encoder0PinB, INPUT);
  Serial.begin (9600);
}

void loop() {
  n = digitalRead(encoder0PinA);
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    if (digitalRead(encoder0PinB) == LOW) {
      encoder0Pos--;
    } else {
      encoder0Pos++;
    }
    Serial.print (encoder0Pos);
    Serial.print ("/");
  }
  encoder0PinALast = n;
}

We Also Recommend


where to buy rotary encoders in toronto

rotary encoder toronto

buy rotary encoder toronto