Created Wed, 18 Apr 2012 08:49:43 +0000 by zampi91
Wed, 18 Apr 2012 08:49:43 +0000
Hello to all ... I have the need to use a rotary encoder, but the interrupt does not support the CHANGE.
How can I do? I currently use this function, recall during the loop:
int8_t read_encoder()
{
static int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
static uint8_t old_AB = 0;
old_AB <<= 2; //remember previous state
old_AB |= (digitalRead(aPin) * 2) + digitalRead(bPin); //add current state
delay(100);
return ( enc_states[( old_AB & 0x0f )]);
}
Read errors often occur when the encoder is turned too quickly.
Is there any way to handle the interrupt when the encoder is rotated?
Thanks for your time. I apologize for my English. :D :D