Implementing Time into basic If Statements

Need beginner advice. My group and I want to send a signal via bluetooth when a certain pin detects an analog signal of 1023. Easy enough. However, due to an unknown voltage leak, the signal will send 1023 at random times for a short period. How can we program this so that: if analogRead=1023 for more than x seconds, then send the output bluetooth signal.

Set up a counter. Every time you sample, if its == 1023, add 1 to the counter. If the sample is something else, clear the counter. Once the count reaches 50 or whatever, call it an event. And clcear the counter for the collection.