Problems with a double if statment

The code has multiple parts to it.
1 part is a led that just pulses through out the arduino being on.
3 leds turn off with in 5 seconds of each other one at 5 another at 10 then the last at 15 seconds.

A sensor detects light, and is specifically asked to look for any light under the 60 mark.

My main problem however is that I have a reset function. I want my sensor to after it detects light under 60 for around 20 seconds straight to reset the whole program.

However me and my tutor have tried but can’t do this. All we manage to get is 20 seconds to go by then if the light sensor detects any light under 60 it restarts the whole program. However we want it to count those 20 seconds only when it is dark. This means it can only start counting when it is dark.

Any advice would be much appreciated! :smiley:

int led7 = 7;// light that will go off
int led8 = 8;// light that will go off
int led9 = 13; // light that will go off
const int LED = 9; // pulse led
int

unsigned long currentMillis;
unsigned long previousMillis = 0;        // will store last time LED was updated
unsigned long interval = 5 * 1000UL;           // interval at which to blink (milliseconds)
unsigned long interval2 = 10 * 1000UL; // ( 9 * 1000)
unsigned long interval3 =  15 * 1000UL;
unsigned long interval4 =  20 * 1000UL;


long startTime ;                    // start time for stop watch

long elapsedTime ;                  // elapsed time for stop watch

//sensor
int sensorPin = 0;	// light sensor is connected to analog pin 0
int sensorValue;	// variable to store the value coming from the sensor
 


void setup() {
  digitalWrite(led7, HIGH); //makes leds default on
  digitalWrite(led8, HIGH);
  digitalWrite(led9, HIGH);
 
  
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  
  
  
   Serial.begin( 9600);
 
 }
void(* resetFunc) (void) = 0;//declare reset function at address 0

void loop ()
{
 //startTime = millis();
 
  //for sensor
  
 // /*
  Serial.println("And the value is: "); 
sensorValue = analogRead(sensorPin); // read the value of the sensor 
Serial.println (sensorValue);
  /*if (sensorValue >= 100) {	// if the number is above 100,
                   // digitalWrite(ledPin, HIGH);	// turn the LED on
                   Serial.println("too bright");	// send that value to the computer
          }	 
          else {	// otherwise,
                    //digitalWrite(ledPin, LOW);	// turn the LED off
                    Serial.println(sensorValue);	// send that value to the computer
          }
       //   */
  
  //for pulsing l.e.d
  static float in = 4.712; // controls how bright the .e.d goes by setting parameters from 0 -19
  float out;
 
 // do input, etc. here - as long as you don't pause, the LED will keep pulsing
  
  in = in + 0.0005; // changes speed of fade by a lot
  if (in > 10.995)
    in = 4.712;
  out = sin(in) * 127.5 + 127.5;
  analogWrite(LED,out);
  
  //unsigned long currentMillis = millis();
  currentMillis = millis();
  //led7turnoff
  if(currentMillis - previousMillis > interval) {   
    digitalWrite(led7, LOW);
  }
  
  //led8 turnoff
  if(currentMillis - previousMillis > interval2) {   
    digitalWrite(led8, LOW);
  }
  
  if(currentMillis - previousMillis > interval3) {
  //previousMillis = currentMillis;   
    digitalWrite(led9, LOW);
    
    //sensorrestart
    
  }
  //if (currentMillis - previousMillis > interval4) {
    
  if(sensorValue <= 60) {
    
    
    startTime = millis();
    
    
    elapsedTime =   millis() - startTime; 

if ((sensorValue <= 60) && (startTime += interval4))
  {
  
   resetFunc(); //call reset  
  
  

  }    // store elapsed time
  }
  
  /*if ((sensorValue <= 60) && (elapsedTime += interval4))
  {
  
   resetFunc(); //call reset  
  
  

  }
  if ((currentMillis - previousMillis) < (interval4 && sensorValue <= 60)) {
  resetFunc(); //call reset  
  
  }
  */
}

I want my sensor to after it detects light under 60 for around 20 seconds straight to reset the whole program.

Now, think about that. How is the sensor going to reset the program? Is your sensor capable of pressing the reset switch?

Now, having the CODE appear to reset things is a different story.

Posting some code that ACTUALLY compiles would be a good start.

  in = in + 0.0005; // changes speed of fade by a lot

What the f**k does this comment mean?

Ditch ALL commented out code BEFORE posting code. Use Tools + Auto Format BEFORE posting code.

This "(startTime += interval4)" is always TRUE and increments startTime every time.

Thanks for the tip Paul,

And thanks George, should of seen that, been staring at the code for far to long. Thanks for that,
much appreciated