22 lines
517 B
Python
22 lines
517 B
Python
import RPi.GPIO as GPIO
|
|
import asyncio
|
|
|
|
async def button_press(pin:int):
|
|
|
|
GPIO.setwarnings(False)
|
|
GPIO.setmode(GPIO.BOARD) # physical numbers
|
|
|
|
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
while True:
|
|
button_state = GPIO.input(pin)
|
|
if button_state == False:
|
|
pass
|
|
else:
|
|
break
|
|
|
|
GPIO.cleanup()
|
|
asyncio.sleep(1)
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
print(asyncio.get_event_loop().run_until_complete(button_press(19))) |