当我运行代码时,LED会立即打开和关闭,而不会倒计时结束
我尝试了线程计时器和异步
import asyncio
from threading import timer
def CntDwn():
timedout = true
# send on signal to raspberry pi
sendSignal(ON)
def Process():
#if car enters a region
# first i tried using thread timer
t1 = Timer(10.0, countdown('up'))
t1.start()
# using asyncio
task1 = loop.create_task(CntDwn('OFF', 3))
# if another car enters the region
if (not timedout):
# for timer
t1.cance1
# for asyncio
task1.cancel()
t1 = Timer(10.0, countdown('up'))
t1.start()
#if timed out
elif(timedout):
# send off signal to raspberry pi
sendSignal(OFF)
# restart the timer
t1 = Timer(10.0, countdown('up'))
t1.start()
当我运行代码时,led会先打开然后立即关闭而不会延迟