Hello Everyone,
I´m using blynk for a while now to control my two garage doors. According to the linked tutorial, I was able to start and stop both doors (TuerL & TuerR) by using this code:
# TuerL control through V0 virtual pin
@blynk.on("V0")
def v0_write_handler(value):
# global led_switch
if int(value[0]) is not 0:
GPIO.output(TuerL, GPIO.LOW)
else:
GPIO.output(TuerL, GPIO.HIGH)
# TuerR control through V1 virtual pin
@blynk.on("V1")
def v1_write_handler(value):
# global led_switch
if int(value[0]) is not 0:
GPIO.output(TuerR, GPIO.LOW)
else:
GPIO.output(TuerR, GPIO.HIGH)
As travel of the door takes a while and this is very hard to judge if you are not in front of the door, I wanted to create a signal for 22 seconds after the start of the movement that says “doors might be busy” (“BESCHAEFTIGT”).
I did this using a sleep period for 22 seconds and this also works.
The only problem is, that I can’t stop the door or start the other one while the program is “sleeping”.
For this reason, I thought of using shorter sleep-periods within a while loop. But I have no idea how to code the conditions.
# TuerL control through V0 virtual pin
@blynk.on("V0")
def v0_write_handler(value):
# global led_switch
if int(value[0]) is not 0:
GPIO.output(TuerL, GPIO.LOW)
print('linke Tuer aktiv')
iL=0
blynk.virtual_write(4, 'BESCHAEFTIGT')
while **???**:
sleep(1)
iL += 1
blynk.virtual_write(4, 'BEREIT')
else:
GPIO.output(TuerL, GPIO.HIGH)
print('linke Tuer passiv')
# TuerR control through V1 virtual pin
@blynk.on("V1")
def v1_write_handler(value):
# global led_switch
if int(value[0]) is not 0:
GPIO.output(TuerR, GPIO.LOW)
iR = 0
blynk.virtual_write(4, 'BESCHAEFTIGT')
while **???**:
iR += 1
sleep(1)
blynk.virtual_write(4, 'BEREIT')
else:
GPIO.output(TuerR, GPIO.HIGH)
print('rechte Tuer passiv')
Basically the conditions for “TuerL” are:
- iL <22
- V0 is 0
- V1 is 0
Can you please advise me he the code for the while-loop should look like?
Thank you very much in advance.
Michael