Hi, I'm having problems reading an optic encoder, it counts pulses just fine but when it gets to a certain value it resets from another pulse count, this is the code I'm using.
#define ENCA 2 // YELLOW
#define ENCB 3 // WHITE
volatile int posi = 0;
void setup() {
Serial.begin(9600);
pinMode(ENCA,INPUT);
pinMode(ENCB,INPUT);
attachInterrupt(digitalPinToInterrupt(ENCA),readEncoder,RISING);
}
void loop() {
Serial.println(posi);
}
void readEncoder(){
int b = digitalRead(ENCB);
if(b > 0){
posi++;
}
else{
posi--;
}
}
I attached the encoder to a dc motor to try it, it has 430 pulses per revolution
and the serial plotter output is the following
it gets to 32743 and then it goes to the negative value, the motor its spinning only in one direction.
