- Thu May 18, 2017 10:13 am
#194929
I am having trouble programming the E6A2-CS3E rotary encoder with an Arduino Uno. Unlike most encoders it only has three wires, 5V, 0V and Output A. I can't find any example code for this type of encoder. Any advise would be much appreciated.
Datasheet - http://www.mouser.com/ds/2/307/e6a2-c_d ... 597999.pdf
This is the code I found for two output encoders.
Datasheet - http://www.mouser.com/ds/2/307/e6a2-c_d ... 597999.pdf
This is the code I found for two output encoders.
Code: Select all
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;
}