Rotary Encoder Module

$6.95

9 in stock

Description

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;
}

 

Additional information

Weight 0.009 kg

There are no reviews yet.

Be the first to review “Rotary Encoder Module”

Your email address will not be published. Required fields are marked *