tweak
This commit is contained in:
parent
1ee6b2e95c
commit
0c2acdb2ec
39
main.py
39
main.py
@ -1,22 +1,21 @@
|
||||
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 == True:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
|
||||
GPIO.cleanup()
|
||||
await asyncio.sleep(.1)
|
||||
return True
|
||||
#!/usr/bin/env python
|
||||
import pigpio
|
||||
import time
|
||||
import datetime
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(asyncio.get_event_loop().run_until_complete(button_press(19)))
|
||||
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")
|
||||
|
||||
if(pi.read(gpio)==0):
|
||||
i = datetime.datetime.now()
|
||||
date = i.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
print(date)
|
||||
pi = pigpio.pi()
|
||||
pi.set_mode(10, pigpio.INPUT)
|
||||
while True:
|
||||
cbf(10, pigpio.EITHER_EDGE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user