Hello Grant,
Thank you for your response. I think I made a stupid question while I weren’t understanding how to connect Encoder to right pins. As the image below I connected the YELLOW to pin 2 and WHITE to pin 3 (on ArduPilot board) then play with this code but it doesn’t work:
http://s30.postimg.org/sojsids0g/photo_6.jpg
[code]int pulses, A_SIG=0, B_SIG=1;
void setup(){
attachInterrupt(0, A_RISE, RISING);
attachInterrupt(1, B_RISE, RISING);
Serial.begin(115200);
}//setup
void loop(){
}
void A_RISE(){
detachInterrupt(0);
A_SIG=1;
if(B_SIG==0)
pulses++;//moving forward
if(B_SIG==1)
pulses–;//moving reverse
Serial.println(pulses);
attachInterrupt(0, A_FALL, FALLING);
}
void A_FALL(){
detachInterrupt(0);
A_SIG=0;
if(B_SIG==1)
pulses++;//moving forward
if(B_SIG==0)
pulses–;//moving reverse
Serial.println(pulses);
attachInterrupt(0, A_RISE, RISING);
}
void B_RISE(){
detachInterrupt(1);
B_SIG=1;
if(A_SIG==1)
pulses++;//moving forward
if(A_SIG==0)
pulses–;//moving reverse
Serial.println(pulses);
attachInterrupt(1, B_FALL, FALLING);
}
void B_FALL(){
detachInterrupt(1);
B_SIG=0;
if(A_SIG==0)
pulses++;//moving forward
if(A_SIG==1)
pulses–;//moving reverse
Serial.println(pulses);
attachInterrupt(1, B_RISE, RISING);
}
[/code]
Did I do something wrong?