Countdown counter using TCRT500

Hi guys,

My goal is to have a 3digit 7segments countdown counter using analog IR sensor TCRT500. I want each time an object pass at proximity, I want the counter to count -1, until 0, starting at 100.

The actual sketch is able to read the sensor, to count down, but DO NOT COUNT the object for one, but count all way down to 0 while the object is at proximity.

I know that is called "change state counter", but I cannot make working properly, someone to help ?

Here is the sketch:

//Library
#include "SevenSeg.h"

SevenSeg disp (10, 6, 4, 2, 1, 9, 5); //Defines the segments A-G: SevenSeg(A, B, C, D, E, F, G);
const int numOfDigits = 3; //number of digits
int digitPins [numOfDigits] = {11, 8, 7}; //CC(or CA) pins of segment

//Variables
int AmmoCount;
int AmmoMax;
int Threshold;
int LEDvar;
//Variable will change:
int LEDvarState;
int LEDvarLastState;

void setup() {
pinMode (A0, INPUT);
Threshold = 950;
AmmoMax = 100;
AmmoCount = AmmoMax;
LEDvarLastState = 0;
LEDvarState = 0;
//Defines the number of digits to be "numOfDigits" and the digit pins to be the elements of the array "digitPins"
disp.setDigitPins ( numOfDigits , digitPins );
disp.setCommonAnode();
}

void loop()
{
disp.write(AmmoCount);
LEDvar = analogRead (A0);
if (LEDvar > Threshold)
{
LEDvarState = 1;
if (LEDvarState != LEDvarLastState)
{
if (AmmoCount == 0)
{
disp.write("000");
}
else
{
AmmoCount = AmmoCount - 1;

//LEDvarState = 0;
}
}
else
{
LEDvar = 0;
LEDvarLastState = LEDvarState;
}
}
}