volatile int countA = 0;
volatile int countB = 0;
volatile bool flagA = 0;
volatile bool flagB = 0;
void setup() {
attachInterrupt(0, fazaA, CHANGE);
attachInterrupt(1, fazaB, CHANGE);
Serial.begin(9600);
}
void loop() {
Serial.println(countA);
Serial.println(countB);
delay(200);
}
void fazaA(){
if (flagB == 0){
flagA = 1;
}
else{
flagB = 0;
}
countA++;
}
void fazaB(){
if (flagA){
countB++;
flagA = 0;
Serial.println("Forward");
}
else{
flagB = 1;
countB--;
Serial.println("Backward");
}
}