int Dira = 4;
int Speeda = 5;
int HallOa = 16;
int HallTa = 17;

volatile int CountOa = 0;
volatile int CountTa = 0;

volatile int sta = 0;
volatile int stap = 0;
volatile int stb = 0;
volatile int stbp = 0;

void setup() {
  Serial.begin(9600);
  pinMode(Dira, OUTPUT);
  pinMode(HallOa, INPUT_PULLUP);
  pinMode(HallTa, INPUT_PULLUP);
  analogWrite(Speeda,0);
  digitalWrite(Dira, HIGH);
  attachInterrupt(digitalPinToInterrupt(HallOa),ReadOa,CHANGE);
  attachInterrupt(digitalPinToInterrupt(HallTa), ReadTa, CHANGE);
}

void loop() {
 
}

void ReadOa () {
  stap = sta;
  stbp = stb;
  CountOa++;
  sta = digitalRead(HallOa);
  stb = digitalRead(HallTa);
  if( sta == HIGH && stb == HIGH && stap == LOW && stbp ==HIGH) {
      Serial.println("Rueckwaerts");
  }
}

void ReadTa () {
   stap = sta;
  stbp = stb;
  CountTa++;
  sta = digitalRead(HallOa);
  stb = digitalRead(HallTa);
  if( sta == HIGH && stb == HIGH && stap == HIGH && stbp == LOW) {
      Serial.println("Vorwaerts");    
      }
  }


