trouble:
So can anyway tell me the right way to do it in software of course..
I suggest you add some hysteresis to your dawn / dusk thresholds. Your current code doesn't record whether it's currently 'dark' or 'light' so I suggest you add a state variable to record that and only change state when the light level cross the threshold by some margin.
For example:
boolean dark = false;
const int DAWN = 510;
const int DUSK = 490;
if(light)
{
if(analogRead(ldr) < DUSK)
{
dark = true;
// stuff to do when it changes from light to dark
}
}
else
{
if(analogRead(ldr) > DAWN)
{
dark = false;
// stuff to do when it changes from dark to light
}
}
if(dark)
{
// stuff to do while it's dark
}
else
{
// stuff to do while its light
}