help wwith dusk timer on for 7hours then off till next dark period

hi guys having a little trouble trying to figure out how to word a part of my code…

i have made a set of leaping arches for christmas time and i thought i coded properly but my code is turning on and then off after 7 hours but it turns on again due to light level at midnight and will run untill daylight
heres my code

#include <FastLED.h>
#define NUM_LEDS_PER_STRIP 90
int lightPin = 0;  //define a pin for Photo resistor
int lightLevel, high = 0, low = 1023;
long Run = 0;
long on = 0;
long currentMillis = 0;

CRGB leds[NUM_LEDS_PER_STRIP];
int fill = 50;
int chase = 300;
int onTime = 25200000;
void setup()
{
  Serial.begin(9600);
  FastLED.addLeds<NEOPIXEL, 6>(leds, NUM_LEDS_PER_STRIP);
  FastLED.addLeds<NEOPIXEL, 7>(leds, NUM_LEDS_PER_STRIP);

  //clear() turns all LEDs off
  FastLED.clear();
}

void loop()
{
  currentMillis = millis();
  checkLight();
  timer();
  arches();
}

void checkLight()
{
  if (Run == 0)
  { 
  lightLevel = analogRead(lightPin);
  Serial.print("Analog reading = ");
  Serial.println(lightLevel);
  delay(5000);
  } else {
    //do nothing
  }
}

void timer()
{
  if (lightLevel <= 500)
  {
    Run = 1;
    on = millis();
  }
}


void arches()
{
// removed animation sequence due to 9000 char. limit of fourm
  }else{
    Run=0;
    FastLED.clear();
  }
}

now im trying to figure out how to make it stay off untill the next dark period but i cant figure out how to word it by setting run to 2 and then start polling the light sensor waiting for light level again

int onTime = 25200000;

Have you looked at the range of values that will fit in an int on your Arduino?

  checkLight();

Why does this not return true or false (it’s light or it isn’t)?

  timer();
  arches();

Why are these called unconditionally?

I can’t imagine why checkLight() needs to shove its thumb up its ass for 5 seconds.

crap forgot to make that a long value .... and ldrs are slow and it won't exit out of that loop untill it reads a value below 500 so the delay is just so it checks every 5 seconds. the conditions for the next 2 are called in their loops so it has to run thru them and see if their if statements are being met

the conditions for the next 2 are called in their loops so it has to run thru them and see if their if statements are being met

Why? The overhead of two function calls could be avoided by testing ONCE in loop().

but if I call the conditions in the main loop how do I force it into the “sub” loops would I just move my if statements too loop?

void loop()
~~
if( lightLevel < 500)
{
arches()
}
~~

this way I would still need to force it into another loop so I could note millis() to know when to turn off the lights

this way I would still need to force it into another loop so I could note millis() to know when to turn off the lights

loop() is the name of a specific FUNCTION. It is NOT a generic term for function.

You don't need to call the timer() function if it isn't dark, do you? It is impossible to tell, because the function name doesn't mean a thing. What it the Arduino team had decided that digitalRead() should be called s2d211ed()? Meaningful names ARE important.

I don't need it until it's dark but if you look inside the funtion it checks the light level and if it's above 500 it will skip out of it and go to the next funtion and check it's if statements

You are starting your animation whenever it is dark out. I think you really want to start the animation only when it transitions from light to dark (currently dark, previously light).

This is one of the big challenges of programming—defining exactly what is intended. Doing something “when it is dark” is very different from doing something “when it becomes dark.”

–Doug

I don't need it until it's dark but if you look inside the funtion it checks the light level and if it's above 500 it will skip out of it and go to the next funtion and check it's if statements

Having two functions check if it is dark is stupid. Have loop check if it is dark, and only call the functions when the condition is true.

I used the TimeLord Library for calculating dusk and dawn times for a specific location. If you also would like to implement daylight saving time calculations, you can add the Timezone Library.

TimeLord: https://github.com/probonopd/TimeLord Timezone: https://github.com/JChristensen/Timezone

There is a very well written chicken coop example online. Much of the code came with support from the Arduino forum. http://arduino-coop.blogspot.nl/p/source-code.html