this might work
This commit is contained in:
parent
8d74edad0c
commit
d7e6298f47
33
main.py
33
main.py
@ -2,19 +2,30 @@
|
||||
import pigpio
|
||||
import time
|
||||
import datetime
|
||||
import asyncio
|
||||
from functools import wraps, partial
|
||||
|
||||
if __name__ == "__main__":
|
||||
def cbf(gpio, level):
|
||||
if(pi.read(gpio)!=0):
|
||||
i = datetime.datetime.now()
|
||||
date = i.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print("gpio "+str(gpio)+"button gpio gave 1")
|
||||
def async_wrap(func):
|
||||
@wraps(func)
|
||||
async def run(*args, loop=None, executor=None, **kwargs):
|
||||
if loop is None:
|
||||
loop = asyncio.get_event_loop()
|
||||
pfunc = partial(func, *args, **kwargs)
|
||||
return await loop.run_in_executor(executor, pfunc)
|
||||
return run
|
||||
|
||||
if(pi.read(gpio)==0):
|
||||
i = datetime.datetime.now()
|
||||
date = i.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
print(date)
|
||||
# init GPIO
|
||||
pi = pigpio.pi()
|
||||
# button pin
|
||||
pi.set_mode(10, pigpio.INPUT)
|
||||
|
||||
@async_wrap
|
||||
def button_press(gpio:int, level) -> bool:
|
||||
while True:
|
||||
if(pi.read(gpio)==0):
|
||||
return True
|
||||
|
||||
|
||||
cbf(10, pigpio.EITHER_EDGE)
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(button_press())
|
Loading…
x
Reference in New Issue
Block a user