I have a couple of cheap cutedigi encoders. I can get them to read well enough but when using an interrupt it does not seem to work. When the working code is uploaded I can get the value to switch from 1 to 0 as the encoder disk turns. However when I uploaded the not working code it does not seem to read at all.
Working:
#define encoderPinA 3
void setup()
{
Serial.begin(9600); // put your setup code here, to run once:
pinMode(encoderPinA, INPUT_PULLUP);
digitalWrite(encoderPinA, LOW);
}
void loop()
{
int encoderRead = digitalRead(encoderPinA);
Serial.println(encoderRead);
}
Not working:
#define encoderPinA 3
void setup()
{
Serial.begin(9600); // put your setup code here, to run once:
pinMode(encoderPinA, INPUT_PULLUP);
digitalWrite(encoderPinA, LOW);
attachInterrupt(3, encoder, CHANGE);
}
void loop()
{
}
void encoder()
{
int encoderRead = digitalRead(encoderPinA);
Serial.println(encoderRead);
}