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
|
||||
|
||||
async def button_press(pin:int):
|
||||
def button_callback(channel):
|
||||
GPIO.cleanup()
|
||||
return True
|
||||
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BOARD) # physical numbers
|
||||
|
||||
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.add_event_detect(pin,GPIO.RISING,callback=button_callback)
|
||||
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(5)
|
||||
return False
|
||||
asyncio.sleep(1)
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(asyncio.get_event_loop().run_until_complete(button_press(19)))
|
Loading…
x
Reference in New Issue
Block a user