OK i hope you dont mind i changed some of your code. I put in some Debugging and i have a Resistor on the input side just to bring down the values and changed the time for checking
It maybe nothing like you want. But maybe it will be in the right direction
/*
#define LDR A0
#define LED 13
#define LIGHTON 50
*/
int LDR = A0;
int LED = 13;
int LIGHTON = 50;
unsigned long darkStart;
int ldrValue;
void setup(){
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
pinMode(LDR, INPUT);
Serial.begin(9600);
}
void loop(){
ldrValue = analogRead(LDR);
if (ldrValue <= 512){
digitalWrite(LED, HIGH);
darkStart = millis();
}
if ( millis()-darkStart > LIGHTON){
digitalWrite(LED, LOW);
}
Serial.println(ldrValue);
Serial.println(LDR);
delay(500);
}