test
This commit is contained in:
parent
1bbe4f4086
commit
815221a3d2
26
main.py
26
main.py
@ -2,8 +2,16 @@
|
||||
import pigpio
|
||||
import time
|
||||
import datetime
|
||||
import asyncio
|
||||
from functools import wraps, partial
|
||||
from multiprocessing import Process
|
||||
|
||||
def run_in_parallel(*fns):
|
||||
proc = []
|
||||
for fn in fns:
|
||||
p = Process(target=fn)
|
||||
p.start()
|
||||
proc.append(p)
|
||||
for p in proc:
|
||||
p.join()
|
||||
|
||||
PTT_IS_ON = 0
|
||||
|
||||
@ -12,22 +20,18 @@ pi = pigpio.pi()
|
||||
# button pin
|
||||
pi.set_mode(10, pigpio.INPUT)
|
||||
|
||||
async def button_press(gpio:int, level) -> bool:
|
||||
def button_press(gpio:int, level) -> bool:
|
||||
while True:
|
||||
print("a")
|
||||
if(pi.read(gpio)!=0):
|
||||
PTT_IS_ON = 1
|
||||
if(pi.read(gpio)==0):
|
||||
PTT_IS_ON = 0
|
||||
asyncio.sleep(.5)
|
||||
time.sleep(.5)
|
||||
|
||||
async def ptt():
|
||||
def ptt():
|
||||
while True:
|
||||
print("b")
|
||||
if PTT_IS_ON == 1:
|
||||
print("HEEEEEE")
|
||||
|
||||
time.sleep(.5)
|
||||
if __name__ == "__main__":
|
||||
loop = asyncio.get_event_loop()
|
||||
tasks = asyncio.gather(button_press(10, pigpio.EITHER_EDGE), ptt())
|
||||
asyncio.get_event_loop().run_until_complete(tasks)
|
||||
run_in_parallel(button_press(10, pigpio.EITHER_EDGE), ptt())
|
Loading…
x
Reference in New Issue
Block a user