Hello Everyone.
I am trying to use a Rotary Encoder but is i add a delay to the code the rotary encoder will always read in the same direction.
Can anyone help??
Thanks.
#define outputA 6
#define outputB 5
int angle = 0;
int aState;
int aLastState;
void setup(void)
{
Serial.begin(9600);
/**/
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
/**/
}
void loop(void)
{
aState = digitalRead(outputA);
if (aState != aLastState){
if (digitalRead(outputB) != aState) {
angle ++;
}
else {
angle --;
}
Serial.print("Position: ");
Serial.println(angle);
}
aLastState = aState;
delay (100); //with this delay it doesnt work //
}