Simple garden lights(solar)

The objective of this bit of the program is: A dusk to dawn timer using an LDR which turns the lights on at dusk and OFF at midnight or so, not waiting for dawn. At dusk on the first loop it starts a counter (Count). At dawn, Count is divided by 2 in (HalfTime), then zeroed. On the second and subsequent dusk to dawn period I want to turn the lights off when Count = HalfTime. As Count gets shorter through Summer so does HalfTime. This will reduce the required battery recharge time. I still want Count to carry on counting even though HalfTime has turned the lights off.
My problem is that I can’t retain HalfTime in the dusk/dawn period. Wherever I zero Count it zeroes HalfTime. It’s driving me mad. I’m missing something basic.
Any advice or pointers much appreciated. My first post. Please point out bad practice if any

Code:

int LED = 9;
int LDR = A0;
int HalfTime;
int Count;
void setup()
{
Serial.begin(9600);//for debugging
pinMode(LED, OUTPUT);
pinMode(LDR, INPUT);
}
void loop()
{

int LDRValue = analogRead(LDR);
//Serial.print("sensor = ");
//Serial.println(LDRValue);

if (LDRValue <1000)// ie is dark - turn lights on
{
Count++;
digitalWrite(LED,HIGH);
Serial.print("Count lights are on = ");
Serial.println(Count);
//if Count = HalfTime LED,LOW etc
Serial.print("HalfTime light on = ");
Serial.println(HalfTime);
}
else
{
HalfTime=Count/2;
digitalWrite(LED,LOW);
Serial.print("HalfTime light off = ");
Serial.println(HalfTime);
Count = 0;
Serial.print("Count lights off = ");
Serial.println(Count);
}
delay(3000);
}

int HalfTime;
int Count;

Will an int data type hold the numbers that you expect without rolling over? Will either number ever be negative?

On the first pass through loop() when LDRValue is 1000 or greater the variable Count is set to zero. On the next pass through loop() HalfTime is set to zero/2, which is zero.

Is this your problem? Your text is a bit difficult for me to understand, since you say that Count should carry on counting but you purposely set it to zero.

Thanks for this. groundFungus. If I make the loop delay 15 mins the 12 hour period dusk to dawn will only amount to Count = 48 so I don't think it's an issue.

Blue Eyes..let me clarify... at dusk I want Count to be zero so that when it gets to dawn it knows how long the night was, varying summer to winter.The number of loops depends on 'delay'. Having got a Count for dusk to dawn of say 50, I want the lights to turn off at Count = 25, which is what Count/2 is, but carry on counting so that it knows how long the night was to make the HalfTime number correct for the next day. Count needs to be reset to zero at the beginning of each dusk to dawn period. I want HalfTime to be known during the dusk to dawn period. It then needs to be recalculated at dawn to the new Count/2. You are right. That is my problem.
This certainly forces the mind into logically thinking!

Nothing better to do, so I wrote my own take on this.
Compiles. but untested. So I don’t know if it works.
Might give you some ideas though.
Leo…

const byte ledPin = 9;
const byte ldrPin = A0; // LDR between pin and ground, with 100k pull up resistor
int ldrValue = 800; // dusk light level
boolean lightOn, firstRun = true; // no night duration data yet
int duskConfidence, dawnConfidence, testTime = 1000; // in seconds
unsigned long currentMillis, previousMillis, duskMillis, dawnMillis, burnMillis;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  currentMillis = millis(); // update with each loop
  if (currentMillis - previousMillis > 1000) // test each second
  {
    if (analogRead(ldrPin) > ldrValue) // if night
    {
      if (duskConfidence == 0) duskMillis = currentMillis; // mark dusk
      if (duskConfidence < testTime) duskConfidence++; // increase
      else { // if dusk test time has passed
        if (!lightOn) digitalWrite(ledPin, HIGH); // if LED was off, turn on
        lightOn = true; // remember LED is on
        if (firstRun) burnMillis = 21600000; // 6 hour first run
        else {
          burnMillis = (86400000 - duskMillis - dawnMillis) / 2; // (24hours - dayhours) / 2
          firstRun = false;
        }
      }
      if (dawnConfidence > 0 && dawnConfidence < testTime) dawnConfidence--; // false positive, decrease
    }
    else // if day
    {
      if (dawnConfidence == 0) dawnMillis = currentMillis; // mark dawn
      if (dawnConfidence < testTime) dawnConfidence++; // increase
      if (dawnConfidence >= testTime) lightOn = false; // if sure it's daytime, arm LED
      if (duskConfidence > 0 && duskConfidence < testTime) duskConfidence--; // false positive, decrease
    }
    if (currentMillis > duskMillis + burnMillis) digitalWrite(ledPin, LOW); // LED off
    previousMillis = millis(); // update
  }
}

Thanks to everyone who looked and those who answered. I cracked it eventually. Simple in the end. This measures the night length with Count++. On DARK it goes to LightsOn. On the first loop through it does nothing because it has Count but no ToMorrow. When LIGHT it does nothing. On DARK it has both Count and ToMorrow(half of last nights’ length) so it turns the lights off about midway through the night. It carries on counting to get the next nights’ halftime. At least I know what I mean! Now I need to store ToMorrow in EEPROM

int LED = 9;
int LDR = A0;
int ToMorrow;
int HalfTime;
int Count;
void setup() 
{ 
Serial.begin(9600);//for debugging
pinMode(LED, OUTPUT);
pinMode(LDR, INPUT);
}
void loop()
{
int LDRValue = analogRead(LDR);
Serial.print("sensor = ");
Serial.println(LDRValue);
if (LDRValue <900) // ie is dark - turn lights on
  {  
  LightsOn(); //goto lightsOn
  HalfTime=Count/2;
  Count++;  //increase Count while dark    
  }
  else
  { 
  digitalWrite(LED,LOW);
  Count =0;
  ToMorrow = HalfTime;
  }  
  { 
  delay(600000);
  }
  }
void LightsOn()
  {
    if (Count>ToMorrow)
    {
     digitalWrite(LED,LOW);
    }
    else
  { 
  digitalWrite(LED,HIGH); 
  }
  }