create a incrementing delay, I think...

I am using a photocell to write digital pin 3 high or low.
I have this code working great.
Now I want to add a delay or timer function while pin 3 is low.

This is my code;

int photocellPin = 0;
int photocellReading;
         

void setup()
{  
  Serial.begin(115200);

  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
 
}

void loop()
{
  photocellReading =analogRead(photocellPin);
 
  if (photocellReading > 980) digitalWrite(3, HIGH);


 //good reading//
  if (photocellReading < 980)
    {
     digitalWrite(3,LOW);
    }
}

In the "good reading" if statement. I want to write pin 3 low and wait "X" time to continue, and then the next time the code comes around I want to add 1 millisecond to x, so now x=x+1ms. and continue doing this until x = 5 seconds.

I just cant wrap my brain around these timing things.

Any help would be greatly appreciated. Thanks in advance.

Why? What is this output being used for?

delay() blinds the Arduino. It can't do anything except continue outputting whatever it was outputting. That is usually a bad idea.

My understanding of the requirements is it should take a reading every millisecond. If the reading is low then it can be lazy and take 2 milliseconds, then 3... But you could just keep reading every millisecond and use some other rule to decide whether or not to act upon an individual reading.

Also, does X ever get reset to 1?

The output is being used to turn on /off a relay.
I knew a delay wasn't the best method to use and I was looking at some of the other posts trying to understand how to write a counter but I couldn't wrap my head around it.

I am trying to use this to test a electronic module with a display to see if I can get it to lock up. I am trying to do this by:

turn on relay( controls power to the module)
wait for photocell to see the display is on,
turn off relay
wait "X"
start over.

"X" would start at 1ms and add 1ms with each loop, "X" would be reset to 1ms after 10000 loops.

Does this help understand what I am trying to do?

Try this

const int ledPin =  LED_BUILTIN;

int ledState = LOW;

unsigned long previousMillis = 0;
long interval = 1;
boolean testing = true;

void setup()
{
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  if (testing)
  {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval)
    {
      previousMillis = currentMillis;
      if (ledState == LOW)
      {
        ledState = HIGH;
      }
      else
      {
        ledState = LOW;
      }
      digitalWrite(ledPin, ledState);
      interval += 100;
      Serial.print("interval : ");
      Serial.println(interval);
      if (interval >= 2000)
      {
        Serial.print("Test complete");
        testing = false;
      }
    }
  }
}

Most of the code was borrowed from the BWoD example

Thanks I was just looking at the BWoD reference again .....

Also have a look at Using millis() for timing. A beginners guide, and Several things at the same time

What is the definition of "lock up"? Fails to brighten after Y milliseconds from the output going HIGH?

lockup is when the microprocessor in the display fails to turn on the display, but still has power applied.

What kind of relay are you using?

A 1-millisecond cycle time is pretty short for the average mechanical relay.

Can you use a MOSFET (e.g.) in its place?

Actually using a mosfet, just used relay as a generic term.

I have that portion working. Photocell see the display on and turns off the "relay"
Photocell see the display off and turns the "relay" on