LR Detector LED Counter

I’m currently working on an ammo counter, and I have almost everything working perfectly, however, I can’t seem to get the IR detector I’m using to work quite how I need. I’ve figured how to make it count down, but it just counts down as along as the line between it and the IR emitter is broken, but I want it to count down once per break.

Here’s the full code I have right now, the IR Setup is entirely from the Analog Calibration example sketch, so I’m not sure how much if it I actually need (still fairly new to Teensy/Arduino)

#include <Bounce2.h>
#include "SevSeg.h"
byte counter = 0;
byte setcounter = 18;

//display part
byte DisplayBrightness = 75;
byte NumDigits = 2;
byte DigitPins[] = {14, 13};
byte SegmentPins[] = {16, 15, 6, 7, 9, 17, 18, 8};
SevSeg sevsegdisplay;

//button part
byte ButtonPins[] = {21, 2, 3};
byte ButtonDebounceTime = 5;
Bounce buttons[sizeof(ButtonPins)];


//IR Setup
// These constants won't change:
const int sensorPin = 21;    // pin that the sensor is attached to
const int ledPin = 10;        // pin that the LED is attached to
// variables:
int sensorValue = 0;         // the sensor value
int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
//End IR Setup


void setup() {
  //setup display
  sevsegdisplay.begin(COMMON_CATHODE, NumDigits, DigitPins, SegmentPins);
  sevsegdisplay.setBrightness(DisplayBrightness);

  //Turn on IR LED
  pinMode(12, OUTPUT);
  digitalWrite(12, HIGH);

  //setup buttons
  for(byte i = 0; i < sizeof(ButtonPins); i++){
    //No need to call pinMode yourself this way :D
    buttons[i].attach(ButtonPins[i], INPUT);
    buttons[i].interval(ButtonDebounceTime);
  }
  

    //IR Setup
      // turn on LED to signal the start of the calibration period:
  pinMode(11, OUTPUT);
  digitalWrite(11, HIGH);
  pinMode(12, OUTPUT);
  digitalWrite(12, HIGH);

  // calibrate during the first five seconds
  while (millis() < 5000) {
    sensorValue = analogRead(sensorPin);

    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }

    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }
  }

  // signal the end of the calibration period
  digitalWrite(11, LOW);  
  //End IR Setup


}

void loop() {

//IR Setup
  // read the sensor:
  sensorValue = analogRead(sensorPin);

  // apply the calibration to the sensor reading
  sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);

  // in case the sensor value is outside the range seen during calibration
  sensorValue = constrain(sensorValue, 0, 255);

  // fade the LED using the calibrated value:
  analogWrite(ledPin, sensorValue);
//End IR Setup

  if(sensorValue < 64){
    counter--;
  }
  
  for(byte i = 0; i < sizeof(ButtonPins); i++){
    buttons[i].update();
  }
    
  if(buttons[2].fell()){
    counter++;
  }
  if(buttons[1].fell()){
    counter = setcounter;
  }
  
  sevsegdisplay.setNumber(counter, 0);
  
  sevsegdisplay.refreshDisplay();
}

This is the IR set I’m using