I'm building my first timer in Python and looking into time module. This is what I want:
Inside while loop, when the if condition "A" is true for the first time, start timer
When 10 seconds has passed, trigger an event
When 30 seconds has passed, clear timer so that it's ready to start again when if condition "A" is true
I feel like I have all the building blocks but still cannot get my head around for starting the 10 second timer. In pseudocode, I want this:
if current_time - the_time_from_first_if_statement_match > 10:
do something
This is what I have now. Any help appreciated!
def main():
start_time = time.time()
time_limit = 10
while True:
current_time = time.time() #keeps updating
matchresult = video_process.match
if matchresult == True:
elapsed_time = current_time - start_time #can be anything like 14 or 100 at this point, I'd just want a 10 sec timer
if elapsed_time > time_limit:
print("do something")
Something along these lines:
while True:
while not condition:
...
start_time = ...
while elapsed_time < 10:
...
do_something
while elapsed_time < 30:
...