The problem is, variable t1
is inside the loop, but I can't use it outside (because it's not defined); So the program returns "UnboundLocalError: local variable 't1' referenced before assignment". I don't know other ways to measure the time between this two events, each time the first starts (self explanatory with the code below).
if status in STATUSON:
t1 = 0
GPIO.output(17,GPIO.HIGH)
time.sleep(0.5)
GPIO.output(17,GPIO.LOW)
return statement('Ok')
t1 = time.time()
elif status in STATUSOFF and time.time() - t1 >= 5:
GPIO.output(17,GPIO.HIGH)
time.sleep(0.5)
GPIO.output(17,GPIO.LOW)
return statement('Ok')
elif status in STATUSOFF and time.time() - t1 <= 5:
GPIO.output(17,GPIO.HIGH)
time.sleep(0.5)
GPIO.output(17,GPIO.LOW)
time.sleep(2)
GPIO.output(17,GPIO.HIGH)
time.sleep(0.5)
GPIO.output(17,GPIO.LOW)
return statement('Ok')