Two LEDs with sensor and Millis

I’m making a code for Arduino wherein if the sensor senses something, a timer starts which has an endtime of 2 seconds, and if the sensor senses something within 2 seconds, led turns on and off. If nothing is sensed within 2 seconds, led2 turns on and off.

unsigned long periodStartMillis;
unsigned long currentMillis;
const unsigned long period = 2000;  //period during which button input is valid
byte currentButtonState;
byte previousButtonState;
int count = 0;
boolean printFinalMessage = true;
unsigned long debounceStartMillis;
unsigned long debouncePeriod = 20;
boolean debouncing = false;
int led = 13;
int led2 = 12;
int sensor = 7;
void setup()
{
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(sensor, INPUT);
  Serial.begin(115200);
}

void loop()
{
digitalWrite(led, LOW);
digitalWrite(led2, LOW);
if (digitalRead(sensor == HIGH))
{
  currentMillis = millis();
 if (digitalRead(sensor == HIGH))
 {
  if (currentMillis - periodStartMillis <= period)
  {
  digitalWrite(led, HIGH);
  delay(3000);
  digitalWrite(led, LOW);
  }
 }
  else 
  digitalWrite(led2, HIGH);
  delay(3000);
  digitalWrite(led2, LOW);
}  
}
if (digitalRead(sensor == HIGH))

So, you are reading from the TRUE pin or the FALSE pin. How's that working for you?

There is no excuse for using delay() in a program using millis().

What IS the problem?

I suspect you actually meant

if (digitalRead(sensor) == HIGH)

Not what you put.

PaulS: if (digitalRead(sensor == HIGH))

So, you are reading from the TRUE pin or the FALSE pin. How's that working for you?

There is no excuse for using delay() in a program using millis().

What IS the problem?

Apologies, the problem is I don't know how to use millis in this context. I've tried reading up on Using millis() for timing. A beginners guide, but I still don't get how to apply it to code, so I tried the hands-on approach with this code, I was hoping that someone would help me by pointing out the errors in the code.

4scires: I'm making a code for Arduino wherein if the sensor senses something, a timer starts which has an endtime of 2 seconds, and if the sensor senses something within 2 seconds, led turns on and off. If nothing is sensed within 2 seconds, led2 turns on and off.

I'm not clear on what you mean there.

Does this "and if the sensor senses something within 2 seconds" mean the same sensor sensing some new thing within the 2 second timer that it just started?

Does this "If nothing is sensed within 2 seconds, led2 turns on and off." mean that during that 2 seconds led2 activates if nothing is sensed (and by implication led1 takes over then) or does it mean that when the 2 seconds is over, and nothing had been detected, led2 activates?

So have you corrected the two errors I pointed out in reply #2? Same mistake made in two places

If you have please acknowledge this and perhaps even post the code again. We rely on you to cooperate with out this it is almost impossible to help.

If not why not, it is a mistake even though it will compile.