This is a very general answer, but I think it applies to your situation. What you are describing is pretty similar to de-bouncing contacts, right? Of course you didn't mention whether you care about the input needing to stay LOW for 2 seconds too, but I'll get to that in a moment. The nice thing about dealing with micro-controllers is that a lot of tasks like you are describing can be handled purely in software.
Lets assume the simple case of a single threaded environment, meaning all your tasks get called at some point in a big loop. This is generally called a 'round robin" approach. Well I'm sure your controller has a method of checking a system millisecond timer. So within one of your "round robin" tasks, lets call it checkInput(), you need to set up some "static" variables (meaning they retain their value when the function returns and is called again). One of those variables can be called "lastState", and can be set to 0 initially. You also want another variable called "lastTime", which for simplicity can also be initially set to zero.
So when your program calls checkContacts, you want to do something like this...
- Read the current state of the GPIO input, and compare it to "lastState". If the current state is equal to "lastState", you "return" the value of lastState from the function without doing anything.
- Assuming the current state has changed, you next want to read the system millisecond timer into a temp variable, and subtract the value stored in lastTime. You said you wanted two seconds, so if the difference is found to be less than 2000 (2000mS == 2 seconds), again you return 'lastState' and do nothing.
- if indeed the difference has met or exceeded 2000, then you store the current value of the GPIO input in "lastState, AND store the current millisecond timer value in LastTime. Again, return the value of "lastState.
So now, checkInput() always returns the time-qualified input state. You'll just want to make sure it gets called often enough for whatever level of accuracy you deem acceptable.
There are several good things about this arrangement. Besides it requiring no additional hardware, your 2000mS timer is easy to alter, and you can easily fine tune it to operate differently depending on the transition. For example, you said you want the input to only register "HIGH" when its been that way for 2 seconds, but you can easily have a different time for the reverse case (maybe you don't want any repeats unless the input has been low for 20 seconds!). Another nice thing is that the GPIO pin doesn't always need to be an input. For example, I have a system where each button has a LED indicating the last button pushed, and that LED is powered by the same GPIO lines I use to sense button presses. All I have to do is set the GPIO pins as "inputs" when I enter my function, check my states, and then restore the GPIOs to being outputs before I return. Bottom line, a software only solution will offer you maximum flexibility, and lowest parts count.