Skip to content

Cant understand code #75

@kotopuz

Description

@kotopuz

I cant understand how you read encoder inputs.
There is some array then some weird calcs. There is A and B channels. Generally when A comes you count pulse. Then inside A interrupt you may compare to B state to determine direction. Can you direct me to explanation of this code please

const int QEM [16] = {0,-1,1,2,1,0,2,-1,-1,2,0,1,2,1,-1,0}; // Quadrature Encoder Matrix
static unsigned char New, Old;

void encoderInt() { // handle pin change interrupt for D2
Old = New;
//New = PIND & 3; //(PINB & 1 )+ ((PIND & 4) >> 1); // Mauro Manco
New = digitalRead(encoder0PinA)*2 + digitalRead(encoder0PinB);
encoder0Pos+= QEM [Old * 4 + New];
}

Thanks !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions