If statement with time condition

I want to make a project where if the pin 2 get high for more than 5 seconds, pin 9 will be high and 9 pin will remain high untill i reset it. I need the programme statement. please!

When is our assignment due to be handed in?

Hint: use millis() to timestamp the transition of pin 2 from LOW to HIGH

i made this programme, actually here are some mistakes

unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 5000;
bool val;
void setup()
{
pinMode(9, OUTPUT);

}

void loop()
{
currentMillis = millis();

  if (digitalRead(2) == HIGH && digitalRead(3)== HIGH) 
  {
      startMillis = millis();
      val=true;

      if (currentMillis - startMillis >= period)
      { digitalWrite(9,HIGH);
      }
  }

if (digitalRead(2) != HIGH || digitalRead(3)!= HIGH)
{
val=false;
}

if (val=true && currentMillis - startMillis >= period) {
digitalWrite(9,HIGH);
}
if (val=false) {
digitalWrite(9,LOW);
}

}

@akkas, your topic has been moved to a more suitable location on the forum.

Introductory tutorials is for tutorials that have been written, not questions. Feel free to write a tutorial one you have mastered your problem :slight_smile:

Oops

Can you also please read How to get the best out of this forum and apply what you learned about code tags to the code that you posted. Thanks.

Hello
Who will or how will be reset pin 9?