tweak
This commit is contained in:
parent
1f34a1eb2e
commit
f1bc06aed3
17
main.py
17
main.py
@ -2,18 +2,21 @@ import RPi.GPIO as GPIO
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
async def button_press(pin:int):
|
async def button_press(pin:int):
|
||||||
def button_callback(channel):
|
|
||||||
GPIO.cleanup()
|
|
||||||
return True
|
|
||||||
|
|
||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
GPIO.setmode(GPIO.BOARD) # physical numbers
|
GPIO.setmode(GPIO.BOARD) # physical numbers
|
||||||
|
|
||||||
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
GPIO.add_event_detect(pin,GPIO.RISING,callback=button_callback)
|
while True:
|
||||||
|
button_state = GPIO.input(pin)
|
||||||
|
if button_state == False:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
asyncio.sleep(5)
|
asyncio.sleep(1)
|
||||||
return False
|
return True
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(asyncio.get_event_loop().run_until_complete(button_press(19)))
|
print(asyncio.get_event_loop().run_until_complete(button_press(19)))
|
Loading…
x
Reference in New Issue
Block a user