reading a sensor and using an if statement

Thanks in advance for the help. I tried to search, but came up empty. I'm new to the Arduino forum. I'm relatively accomplished in audio electronics (analog), but am new to programming and digital electronics. I just purchased my board last week. The electronic components work fine, so I don't need help with the electronics. I apologize if the title of the post isn't exactly helpful, but I couldn't figure out how to describe this in a few words - perhaps that is why the search did not help.

I'm using the following chips:
CD4017BC Decade Counter/Divider with 10 Decoded Outputs
CD 4026 decade counter (controls a FND seven segment LED)

I'm wrote a program and bread boarded a project that that does the following:

I have an infrared transmitter /receiver module where the receiver changes state when the IR bounces off a person when they go near the transmitter. When it is not reading a bounce, two LEDS flash back and forth. When it reads the bounce, the program triggers a 4017 chip (Johnson counter) to run 10 LED's in a sequence from one to another. The idea is this contraption is put on, say a Christmas tree, and when someone gets near the tree, the flashing LED's change from flashing to a sequential on off in a row. Also, each time the IR changes state, it increments a counter through a 7 segment LED via a 4026 controller, counting the number of times the IR changes sate (up to 100, then is starts over).
The following program works fine and does exactly what I want it to. My problem is that I want to have the sequencing LEDS stay sequencing for a few seconds even though the IR chip has changed back to its original state. The code below toggles the changes the LED functions as soon as the IR changes state. I can't figure out how to hold the sequential LED's in the if statement even though the sensor has changed state. I have comments in the code that should help make this clear. I've tried for loops and an array with no luck. Any ideas?

/*Program to toggle 4017 timer and flashing LED when IR is triggered or reset.
This also triggers a counter to increment every time the IR is triggered and will reset to 0 when resetting program.
The two LEDS flash when the IR is high, that is not bouncing. Triggering IR stops LEDS from flashing and triggers sequential LEDS via 4017.
In the meantime, the counter tracks the number of times the IR is toggled.
Resetting program (turns off and on) resets counter to 0 count .
4026 interfaces with 7 segment LED. Each pulse advances number by 1.*/

  #define inpin 2 //reads from IR: 5V no reflection, 0 V with reflected IR from object
  #define ledpin1 4  //LED
  #define ledpin4 3 //LED
  #define ledpin2 12 //to 4017
  #define ledpin3 7  // Counter
  #define reset 9 // reset pin
  int inVal = 0;
  void setup()
  {
    pinMode(inpin, INPUT);      // Set pin 2 for input
    pinMode(ledpin1, OUTPUT);   // sets pin  4  for output to LED
    pinMode(ledpin4, OUTPUT);   // sets pin 3 for output
    pinMode(ledpin2, OUTPUT);   // sets pin  12 for output 4017
    pinMode(ledpin3, OUTPUT);   // sets pin  7  for output Timer 4026
    pinMode(reset, OUTPUT);    // sets reset pin to output
  // initialize state of pins
    digitalWrite (reset, HIGH); // resets timer at the start of the program
    digitalWrite (ledpin1, HIGH); // LED
    digitalWrite (ledpin4, LOW); // LED
    digitalWrite (ledpin2, LOW); // 4017 (johnson counter)chip that squences 10 LED's one after another 
    digitalWrite (ledpin3, LOW); // counter: ito 4026 chip
    digitalWrite (reset, LOW); //resets counter and returns it to 0 count
  }
void loop()
   {
      inVal = digitalRead(inpin); // sets function for read of pin 2
      if (inVal == LOW) //IR bounces and changes state to 0 VOLTS (LOW) and triggers if statement below
      {
        digitalWrite(ledpin3, HIGH); //Timer changes from Low to High
        digitalWrite (ledpin1, LOW); //LED shuts off
        digitalWrite (ledpin4, LOW); //LED shuts off
        digitalWrite(ledpin2, HIGH); // Pulses start to 4017
        delay (100);
        digitalWrite (ledpin3, HIGH); //Timer stays High so it does not trigger
        digitalWrite (ledpin1, LOW); //LED stays off
        digitalWrite(ledpin2, LOW); // Pulses start to 4017
        digitalWrite (ledpin4, LOW); //LED shuts off
        delay (100);
        
        //NOTE: I want this to happen for 10 seconds even if the inVAl returns to high
      }
      else
      {
         //I WANT THIS to start ten seconds after the if statement above occurs, not right away
        //ledpin1 and 4 are flashing LEDS that alternate when IR is HIGH (not reflecting)
        digitalWrite (ledpin1, HIGH); // LED return High
        digitalWrite (ledpin4, LOW); // LED return LOW
        digitalWrite (ledpin2, LOW); // 4017 Stops flashing
        digitalWrite (ledpin3, LOW); // Timer remains low to wait for next trigger
        delay(300);
        digitalWrite (ledpin1, LOW); // LED return LOW
        digitalWrite (ledpin4, HIGH); // LED return High
        digitalWrite (ledpin2, LOW); // 4017 Stops flashing
        digitalWrite (ledpin3, LOW); // counter remains low to wait for next trigger
        delay(300);
      }
   }
     [/ code]

I think you might do well to study how the blinkWithoutDelay works...

What you need to understand is the concept of the "Finite State Machine". Everything you have described can be directly described by a distinct state of an FSM.

For more information: http://hacking.majenko.co.uk/finite-state-machine

Thanks. They both look helpful. Looks like I have some homework to do. If there is interest, I'll post the final code that works.