- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.py
More file actions
Latest commit
33 lines (29 loc) · 770 Bytes
/
Copy pathbutton.py
File metadata and controls
33 lines (29 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#button
importtime
importRPi.GPIOasGPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
classButton:
def__init__(self, pin):
self.pin=pin
GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)
self.state=1
self.lastdebounce=0
defrun(self):
elapsedtime=time.time()-self.lastdebounce
ifelapsedtime<0.01:
returnFalse
self.lastdebounce=time.time()
state=GPIO.input(self.pin)
#print(self.state,state)
pushed=False
ifself.state>state:
pushed=True
self.state=state
returnpushed
if__name__=='__main__':
btn=Button(27)
whileTrue:
time.sleep(0.001)
ifbtn.run()==True:
print('pressed')