Hello all,
I have bought some rotary encoders from TME, ED16112O. They do not use the normal grey code. If i rotate them CW i get initial state 00 then 11, 10, then 00 again. CCW it is the exact opposite. I connect the middle pin to GND and the other 2 to 5V.
I have tried it with arduino, got some results using interrupts but i had some misses of rotations.
Can you give me some advice on the code? Thank you.
int pina=2;
int pinb=3;
volatile int x=0;
volatile int trigger=0;
void setup(){
pinMode(pina, INPUT);
pinMode(pinb, INPUT);
attachInterrupt(0, count, RISING);
Serial.begin(9600);
}
void loop(){
Serial.println(trigger);
}
void count(){
if(digitalRead(pinb)==HIGH){
x=2;
};
if(digitalRead(pinb)==digitalRead(pina)){
trigger--;
}
else{
trigger++;
}
}