const int Fl_px1 = 2;
const int Fl_px2 = 3;
const int Bdy_px1 =4;
bool VFl_px1;
bool VFl_px2;
bool VBdy_px1;
const int Hl_px1 =5;
const int Hl_px2 = 6;
int Cow_count =0;
int leg_count =0;
bool leg_countRTrig =LOW;
bool Cow_countRTrig =LOW;
bool Fwd1_1 =LOW;
unsigned long Fl1Millis;
unsigned long PrintMillis;






void setup() {
  // put your setup code here, to run once:
 pinMode(Fl_px1, INPUT);
 pinMode(Fl_px2, INPUT);
 pinMode(Bdy_px1, INPUT);
 pinMode(Hl_px1, INPUT);
 pinMode(Hl_px1, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
unsigned long currentMillis = millis();


if (currentMillis-PrintMillis>2000){
  PrintMillis= currentMillis;
  Serial.println(leg_count);

}


VFl_px1 = digitalRead(Fl_px1);
VFl_px2 = digitalRead(Fl_px2);
VBdy_px1 = digitalRead(Bdy_px1);

if (VBdy_px1){
  Cow_countRTrig = LOW;
  if (VFl_px1){
    Fwd1_1 = HIGH;
  }
  if (Fwd1_1 & VFl_px2 &! leg_countRTrig){
  leg_count++;
  Fwd1_1 = LOW;
  leg_countRTrig = HIGH;
  }
  if (!VFl_px1 &! VFl_px2){
     leg_countRTrig = LOW;
  }
  
  }

 if (leg_count==4 &! VBdy_px1 &! Cow_countRTrig){
  Cow_count++;
  leg_count =0;
 Cow_countRTrig =HIGH;
 }





}