using LDR's as advanced power switch

Hi there!

I making a prototype for my exhibition project and I cant figure out how to program this.
I have two LDR’s (call them sensor1 and sensor2) and a lamp. This is what I am trying to do:

If sensor1 < 300 for 5 seconds than lamp,LOW
If sensor2 < 300 for 5 seconds than lamp, LOW

But if sensor1<300 for example 2 seconds and then sensor2<300 I want to add 5 seconds at the time the lamp goes LOW and vice versa.
So the total delay would be 7 seconds.

After that, if one of the sensors for example sensor2>300 I want to turn the lamp HIGH while sensor1<300 starts to count till 5 again to turn the lamp LOW

I can’t figure it out how to do this!

What I have written so far:

long previousMillis = 0;
int sensor = A0;
int sensor1 = A1;
int lamp = 3;

void setup() {
pinMode(sensor, INPUT);
pinMode(sensor1, INPUT);
pinMode(lamp, OUTPUT);

void loop() {
int sensorValue = analogRead(sensor);
int sensorValue1 = analogRead(sensor1);

unsigned long currentMillis = millis();

if (sensorValue < 300 || sensorValue1 < 300 ){

if (currentMillis - previousMillis > 5000) { //the 5000 are the 5 seconds delay
digitalWrite(lamp, LOW);
// previousMillis = millis();

else if (sensorValue1 > 300 ){
previousMillis = millis();

else if (sensorValue > 300){
previousMillis = millis();

Serial.print("millis “);
Serial.print(” previousMillis ");

what this do:
sensor1<300 = lamp LOW, sensor1>300 = lamp HIGH
sensor2<300 = lamp LOW, sensor2>300 = lamp HIGH

BUT if sensor1<300 & sensor 2<300 changes to sensor1>300 & sensor2<300 the lamps needs turn LOW for 5 seconds

If something is unclear, please ask me.

Thank you in advance!

Do you mean:

If either input is >= 300
set output HIGH.
Reset timer.
Else (meaning both inputs are <300)
Wait until timer reaches five seconds and set output LOW